thecodeholic/yii2-grapesjs

Grapesjs AssetBundle 和小部件

安装: 337

依赖: 0

建议者: 0

安全: 0

星标: 4

关注者: 4

分支: 4

公开问题: 2

语言:JavaScript

类型:yii2-extension

v01.1.8 2019-09-07 14:49 UTC

This package is auto-updated.

Last update: 2024-09-15 17:49:18 UTC


README

Grapesjs AssetBundle,小部件和模块

安装

安装此扩展的首选方式是通过 composer

运行以下命令之一:

php composer.phar require --prefer-dist thecodeholic/yii2-grapesjs "^v0.1.0"

或者

"thecodeholic/yii2-grapesjs": "^v0.1.0"

将其添加到你的 composer.json 文件的 require 部分。

配置

一旦模块安装完成,你需要运行迁移

php yii migrate --migrationPath=@vendor/thecodeholic/yii2-grapesjs/migrations

并在你的配置 modules 中添加模块

'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',
        ]
    ],
    ...
]

配置 AssetManager

该包使用 Yii::$app->fs,因此你需要配置 fs 组件以成为 creocoder\flysystem 的可用目标之一

查看其文档,如果你想指定不同的目标 https://github.com/creocoder/yii2-flysystem

并安装你的目标。

例如

composer require creocoder/yii2-flysystem

在你的控制器中使用小部件

如果你不想使用模块并在控制器中集成,你应该在请求解析器中添加 JsonParser

'request' => [
    'parsers' => [
        'application/json' => 'yii\web\JsonParser',
    ]
]

在你的视图文件中显示小部件。

<?php echo \thecodeholic\yii2grapesjs\widgets\GrapesjsWidget::widget([
    'clientOptions' => [
        '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',
    ]
]) ?>

向你的控制器添加以下操作。

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
    ]);
}