interaction-design-foundation / nova-unlayer-field
Nova 字段,用于 Unlayer 编写电子邮件和着陆页。
2.1.2
2024-02-28 06:24 UTC
Requires
- php: ^8.1
- ext-json: *
- laravel/nova: ^4.20
Requires (Dev)
- interaction-design-foundation/coding-standard: ^0.2.0
- orchestra/testbench: ^8.3
- phpunit/phpunit: ^10.5 || ^11.0
- vimeo/psalm: ^5.22
README
为 Unlayer 添加 Laravel Nova 字段,用于编写电子邮件和着陆页。
安装
您可以通过 composer 在使用 Nova 的 Laravel 应用中安装此包
composer require interaction-design-foundation/nova-unlayer-field
⚠️ 对于 PHP 7.1 - PHP 7.4,请使用 版本 0.2.2(它使用另一个命名空间)。
可选:发布配置
在项目根目录下通过命令行运行此命令
php artisan vendor:publish --provider="InteractionDesignFoundation\NovaUnlayerField\ServiceProvider" --tag=config
用法
此包假设您的模型有一个属性用于存储 Unlayer 设计配置 JSON 字符串(最好使用 json
或 jsonb
或 longtext
SQL 类型来存储)。
在提交时,此包自动仅存储 Unlayer 设计配置(JSON 字符串)。您很可能还希望处理 Unlayer 生成的输出 HTML 代码。要访问它,请使用 savingCallback()
方法(下面有扩展示例)。
基本字段配置
use InteractionDesignFoundation\NovaUnlayerField\Unlayer; public function fields() { return [ Unlayer::make('Content', 'design')->config([ 'projectId' => config('unlayer.project_id'), // optional 'templateId' => config('unlayer.default_template_id'), // Used only if bound attribute ('design' in this case) is empty. 'displayMode' => 'web', // "email" or "web". Default value: "email" 'locale' => 'es', // Locale for Unlayer UI. Default value: application’s locale. ]), ]; }
选项
->config(array|callable $config)
: 指定 Unlayer 配置。->height(string $height)
: 设置编辑器的高度(带单位)。例如 '1000px'(默认为 800px)。->savingCallback(?callable $callback)
: 指定在模型保存之前调用的回调。用于存储生成的 HTML 代码(到模型或作为文件)非常有用。
savingCallback
使用示例
Unlayer::make('Design')->config([ 'projectId' => config('unlayer.project_id'), ]) ->savingCallback(function (NovaRequest $request, $attribute, Newsletter $newsletterModel, $outputHtmlFieldName) { // set output HTML to your model (Newsletter in this case) // No need to call $model->save() — Nova will do it down the road. $newsletterModel->html = $request->input($outputHtmlFieldName); }),
更新日志
请参阅 发布 以获取有关最近更改的更多信息。
贡献
请参阅 CONTRIBUTING 以获取详细信息。
许可证
MIT 许可证(MIT)。请参阅 许可证文件 以获取更多信息。