idf/nova-unlayer-field

此包已被弃用,不再维护。作者建议使用interaction-design-foundation/nova-unlayer-field包。

Laravel Nova 字段,用于Unlayer创建电子邮件和着陆页面。

2.1.2 2024-02-28 06:24 UTC

README

image

Latest Stable Version Total Downloads License

添加Laravel Nova字段,用于Unlayer创建电子邮件和着陆页面。

image

安装

您可以通过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字符串(最好使用jsonjsonblongtext 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)。有关更多信息,请参阅许可证文件