-
Notifications
You must be signed in to change notification settings - Fork 35
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Yii2 Froala Plugin, Update in accordance with Froala PHP SDK #20
Open
puneet0191
wants to merge
13
commits into
froala:master
Choose a base branch
from
puneet0191:module-version-1
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+80
−68
Open
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
62e0ff9
Changes in Composer.json to load SDK
puneet0191 eb18901
Adding imageUploadURL config in widget function
puneet0191 2d5eeff
Creating a Module for Froala Editor
puneet0191 a60b4a3
Adding Controller, with UploadAction which used the SDK upload method
puneet0191 6e9f38e
Minor changes in composer
puneet0191 0019b08
revert b ack version change
puneet0191 9900452
Changes in readme
puneet0191 e963fd4
More updates
puneet0191 be3f288
Updating Composer.json
puneet0191 87d30e1
Read me Changes
puneet0191 2793f4a
Fixing PR comments
puneet0191 e3eabfa
Changed namespace froala/froalaeditor to Froala/Editor
NunoLopesPT 45cc758
Merge pull request #2 from NunoLopes96/pr-1
puneet0191 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,18 +7,27 @@ | |
|
||
## Installation | ||
|
||
The preferred way to install this extension is through [composer](http://getcomposer.org/download/). | ||
The preferred way to install this extension is through [composer](http://getcomposer.org/download/). yii2-froala editor depends on Froala PHP SDK | ||
To use and Install the editor, one must install PHP SDK also. | ||
|
||
Either run | ||
|
||
``` | ||
php composer.phar require --prefer-dist froala/yii2-froala-editor | ||
php composer.phar require --prefer-dist froala/wysiwyg-editor-php-sdk | ||
php composer.phar require --prefer-dist bower-asset/froala-wysiwyg-editor | ||
php composer.phar require --prefer-dist froala/wysiwyg-editor | ||
|
||
``` | ||
|
||
or add | ||
|
||
``` | ||
"froala/yii2-froala-editor": "^2.6.0" | ||
"froala/yii2-froala-editor": "^2.6.0", | ||
"froala/wysiwyg-editor-php-sdk" : "*", | ||
"bower-asset/froala-wysiwyg-editor": "^2.6.0" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same, there is a compose package: https://packagist.org/packages/froala/wysiwyg-editor. |
||
"froala/wysiwyg-editor": "^2.6.5" | ||
|
||
``` | ||
|
||
to the require section of your `composer.json` file. | ||
|
@@ -29,7 +38,7 @@ to the require section of your `composer.json` file. | |
Once the extension is installed, simply use it in your code by : | ||
|
||
```php | ||
<?php echo froala\froalaeditor\FroalaEditorWidget::widget([ | ||
<?php echo Froala\Editor\FroalaEditorWidget::widget([ | ||
'name' => 'content', | ||
'options' => [ | ||
// html attributes | ||
|
@@ -46,7 +55,7 @@ Once the extension is installed, simply use it in your code by : | |
or use with a model: | ||
|
||
```php | ||
<?php echo froala\froalaeditor\FroalaEditorWidget::widget([ | ||
<?php echo Froala\Editor\FroalaEditorWidget::widget([ | ||
'model' => $model, | ||
'attribute' => 'content', | ||
'options' => [ | ||
|
@@ -63,77 +72,29 @@ or use with a model: | |
|
||
## Upload example | ||
|
||
Using the basic Yii template make a new folder under /web/ called uploads. | ||
|
||
For controler: | ||
|
||
```php | ||
public function actionUpload() { | ||
$base_path = Yii::getAlias('@app'); | ||
$web_path = Yii::getAlias('@web'); | ||
$model = new UploadForm(); | ||
|
||
if (Yii::$app->request->isPost) { | ||
$model->file = UploadedFile::getInstanceByName('file'); | ||
|
||
if ($model->validate()) { | ||
$model->file->saveAs($base_path . '/web/uploads/' . $model->file->baseName . '.' . $model->file->extension); | ||
} | ||
} | ||
|
||
// Get file link | ||
$res = [ | ||
'link' => $web_path . '/uploads/' . $model->file->baseName . '.' . $model->file->extension, | ||
]; | ||
|
||
// Response data | ||
Yii::$app->response->format = Yii::$app->response->format = Response::FORMAT_JSON; | ||
return $res; | ||
} | ||
``` | ||
|
||
For model: | ||
Using the Froala PHP SDK with Froala Editor widget, the first step would be to add the configuration in web.php config file, make an entry for Froala Module | ||
in the Config Array. | ||
|
||
```php | ||
namespace app\models; | ||
use yii\base\Model; | ||
use yii\web\UploadedFile; | ||
|
||
/** | ||
* UploadForm is the model behind the upload form. | ||
*/ | ||
class UploadForm extends Model | ||
{ | ||
/** | ||
* @var UploadedFile|Null file attribute | ||
*/ | ||
public $file; | ||
|
||
/** | ||
* @return array the validation rules. | ||
*/ | ||
public function rules() | ||
{ | ||
return [ | ||
[['file'], 'file'] | ||
]; | ||
} | ||
} | ||
'modules' => [ | ||
'froala' => [ | ||
'class' => '\Froala\Editor\Module', | ||
'uploadFolder' => '/uploads/' | ||
] | ||
], | ||
``` | ||
|
||
For the view: | ||
Make sure you have a folder called "uploads" in your web root directory,Now to use the Froala Widget on any view just use the following code in the view: | ||
|
||
```php | ||
<?= \froala\froalaeditor\FroalaEditorWidget::widget([ | ||
<?= \Froala\Editor\FroalaEditorWidget::widget([ | ||
'name' => 'body', | ||
'clientOptions' => [ | ||
'toolbarInline'=> false, | ||
'height' => 200, | ||
'theme' => 'royal',//optional: dark, red, gray, royal | ||
'language' => 'en_gb' , | ||
'toolbarButtons' => ['fullscreen', 'bold', 'italic', 'underline', '|', 'paragraphFormat', 'insertImage'], | ||
'imageUploadParam' => 'file', | ||
'imageUploadURL' => \yii\helpers\Url::to(['site/upload/']) | ||
], | ||
'clientPlugins'=> ['fullscreen', 'paragraph_format', 'image'] | ||
]); ?> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<?php | ||
|
||
namespace Froala\Editor; | ||
|
||
class Module extends \yii\base\Module | ||
{ | ||
public $controllerNamespace = 'Froala\Editor\controllers'; | ||
|
||
// Without false it will give "Bad Request (#400) Unable to verify your data submission." | ||
public $enableCsrfValidation = false; | ||
|
||
public $uploadFolder; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<?php | ||
|
||
namespace Froala\Editor\controllers; | ||
|
||
use yii\web\Controller; | ||
|
||
class DefaultController extends Controller | ||
{ | ||
// Without false it will give "Bad Request (#400) Unable to verify your data submission." | ||
public $enableCsrfValidation = false; | ||
|
||
public function actionUpload() | ||
{ | ||
// Store the image. | ||
try { | ||
$uploadFolder = $this->module->uploadFolder; | ||
|
||
$response = \FroalaEditor_Image::upload($uploadFolder); | ||
echo stripslashes(json_encode($response)); | ||
} | ||
catch (Exception $e) { | ||
http_response_code(404); | ||
} | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is a composer package as well: https://packagist.org/packages/froala/wysiwyg-editor.