https://github.com/thecodeholic/yii2-grapesjs
Yii2 GrapesJs AssetBundle, Actions and module
https://github.com/thecodeholic/yii2-grapesjs
Last synced: 10 months ago
JSON representation
Yii2 GrapesJs AssetBundle, Actions and module
- Host: GitHub
- URL: https://github.com/thecodeholic/yii2-grapesjs
- Owner: thecodeholic
- Created: 2019-08-31T09:51:11.000Z (almost 7 years ago)
- Default Branch: master
- Last Pushed: 2024-02-08T17:19:19.000Z (over 2 years ago)
- Last Synced: 2025-06-17T21:24:15.101Z (12 months ago)
- Language: JavaScript
- Homepage:
- Size: 1.93 MB
- Stars: 6
- Watchers: 3
- Forks: 3
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
Grapesjs AssetBundle and widgets
================================
Grapesjs AssetBundle, widgets and module
Installation
------------
The preferred way to install this extension is through [composer](http://getcomposer.org/download/).
Either run
```
php composer.phar require --prefer-dist thecodeholic/yii2-grapesjs "^v0.1.0"
```
or add
```
"thecodeholic/yii2-grapesjs": "^v0.1.0"
```
to the require section of your `composer.json` file.
Configuration
-----
Once the module is installed, you need to run migrations:
```php
php yii migrate --migrationPath=@vendor/thecodeholic/yii2-grapesjs/migrations
```
And add module in your config `modules`
```php
'modules' => [
'grapesjs' => [
'class' => \thecodeholic\yii2grapesjs\Module::class,
// custom placeholder variables which will be added into richtext
// default is empty array
'grapesJsVariables' => [
'{first_name}' => 'First Name',
'{last_name}' => 'Last Name',
'{age}' => 'Age',
]
],
...
]
```
Configuring AssetManager
------------------------
The package uses `Yii::$app->fs` so you need to configure `fs` component to be one of the available
targets of `creocoder\flysystem`
Checkout its documentation if you want to specify different targets
https://github.com/creocoder/yii2-flysystem
And you need to install your desired target.
For example
```php
composer require creocoder/yii2-flysystem
```
Using the widget in your own controller
---------------------------------------
If you do not want to use the module and integrate in your controller, you should add `JsonParser` in request parser's.
```php
'request' => [
'parsers' => [
'application/json' => 'yii\web\JsonParser',
]
]
```
Display the widget in your view file.
```php
[
'storageManager' => [
'id' => '',
'type' => 'remote',
'stepsBeforeSave' => 1,
'urlStore' => "save?id=$model->id",
'urlLoad' => "get?id=$model->id",
],
'assetManager' => [
'upload' => "upload"
],
'deviceManager' => [
'defaultDevice' => 'Resolution 2',
'devices' => [
[
'name' => 'Resolution 1',
'width' => '850px',
'widthMedia' => '992px'
],
[
'name' => 'Resolution 2',
'width' => '750px',
],
[
'name' => 'Resolution 3',
'width' => '650px'
],
[
'name' => 'Resolution 4',
'width' => '450px',
],
[
'name' => 'Resolution 5',
'width' => '375px',
]
]
]
],
// custom placeholder variables which will be added into richtext
// default is empty array
'variables' => [
'{first_name}' => 'First Name',
'{last_name}' => 'Last Name',
'{age}' => 'Age',
]
]) ?>
```
Add the following actions to your controller.
```php
public function actions()
{
return array_merge(parent::actions(), [
'get' => [
'class' => \thecodeholic\yii2grapesjs\actions\GetAction::class,
// If includeFields is presented `excludeFields` are not considered
// 'includeFields' => ['css', 'html'],
// Exclude assets column from returned fields of the Content model
'excludeFields' => ['assets']
],
'save' => \thecodeholic\yii2grapesjs\actions\SaveAction::class,
'upload' => \thecodeholic\yii2grapesjs\actions\UploadAction::class
]);
}
```