waynestate/nova-ckeditor4-field

此nova包允许您在文本区域中使用CKEditor 4。

1.4.0 2024-07-05 01:14 UTC

This package is auto-updated.

Last update: 2024-09-05 01:38:33 UTC


README

Latest Stable Version Daily Downloads Total Downloads Latest Unstable Version License PHP Version Require

⚠️ CKEditor4 生命周期结束 ⚠️

CKEditor4 已达到半生命周期结束,您可以在此处了解更多信息:CKEditor 4: 2023年6月结束生命周期

不幸的是,要使用 CKEditor4 LTS(任何高于 v4.22.1 的版本),您需要有长期支持

本包不会很快消失,但如果您使用的是 CKEditor4 v4.22.1 或更低版本,您可能会由于 CKEditor 在 CKEditor 端检查版本文件而遇到安全警告(问题95)

由于默认指向 v4.22.1 非LTS CKEditor4,因此在配置中默认禁用了安全警告选项(配置文件)

如果您确实有 CKEditor4 LTS 包,请在更新此包到 v1.4.0 之前,在您的配置中重新启用版本检查。

概述

此nova包允许您使用Nova v4在文本区域中使用CKEditor 4

CKEditor Form Field

安装

Nova v1, v2, v3 兼容性说明

您可以通过composer将包安装到使用Nova的Laravel应用程序中

composer require waynestate/nova-ckeditor4-field

默认使用的CKEditor 4实例是最新版本(4.22.1)全功能版本(https://cdn.ckeditor.com/)。如果您想使用不同的CKEditor 4版本,可以通过发布和编辑配置来实现。

用法

<?php

namespace App\Nova;

use Waynestate\Nova\CKEditor4Field\CKEditor;

class Article extends Resource
{
    // ...

    public function fields(Request $request)
    {
        return [
            // ...

            CKEditor::make('Body', 'body');
                
            // ...
        ];
    }
}

覆盖配置值

要更改任何配置值,请发布一个配置文件

php artisan vendor:publish --tag=nova-ckeditor4-field-config

定制

配置选项

您可以通过编辑在 nova.ckeditor-field.options 发布的配置文件或使用 options 方法传递来更改CKEditor实例的配置选项

    /*
    |--------------------------------------------------------------------------------
    | CKEditor Options
    |--------------------------------------------------------------------------------
    |
    | To view a list of all available options checkout the CKEditor API documentation
    | https://ckeditor.npmjs.net.cn/docs/ckeditor4/latest/api/CKEDITOR_config.html
    |
    */
    'options' => [
        'toolbar' => [
            ['Source','-','Cut','Copy','Paste','PasteText','PasteFromWord','-','Print', 'SpellChecker', 'Scayt'],
            ['Undo','Redo','-','Find','Replace','-','SelectAll','RemoveFormat'],
            ['Image','Table','HorizontalRule','SpecialChar','PageBreak'],
            '/',
            ['Bold','Italic','Strike','-','Subscript','Superscript'],
            ['NumberedList','BulletedList','-','Outdent','Indent','Blockquote','CreateDiv'],
            ['JustifyLeft','JustifyCenter','JustifyRight'],
            ['Link','Unlink','Anchor'],
            '/',
            ['Format','FontSize'],
            ['Maximize', 'ShowBlocks','-','About']
        ]
    ],

来更改CKEditor实例的配置选项

public function fields(Request $request)
{
    return [
        // ...

        CKEditor::make('Body', 'body')->options([
            'height' => 300,
            'toolbar' => [
                ['Source','-','Cut','Copy','Paste'],
            ],
        ]),

        // ...
    ];
}

文件上传

nova-ckeditor4-field 允许通过扩展Trix字段的附件功能来使用文件上传

php artisan vendor:publish --tag=nova-ckeditor4-field-config # Make sure the config file is published
php artisan migrate # Run the migrations

在运行 php artisan migrate 时,包迁移会自动运行。

如果您不打算使用文件,并且没有需要迁移的,您可以在 config/nova/ckeditor-field.php 中禁用迁移,将 enable_migrations 设置为 false

    'migrations' => [
        'enable_migrations' => false,
        // ...
    ],

如果您不希望使用 Laravel迁移,但想自己发布迁移到您的项目中,请将 auto_migrate 设置为 false

    'migrations' => [
        'enable_migrations' => true,
        'auto_migrate' => false,
    ],

然后发布迁移到您的项目中。

php artisan vendor:publish --tag=nova-ckeditor4-field-migrations

如果您不想使用默认的 Attachment 和/或 PendingAttachment 模型,您可以在发布的 /config/nova/ckeditor-field.php 中用您自己的替换。

    'attachment_model' => \Waynestate\Nova\CKEditor4Field\Models\Attachment::class,
    'pending_attachment_model' => \Waynestate\Nova\CKEditor4Field\Models\PendingAttachment::class,

使用文件上传功能需要CKEditor使用插件 增强图像(image2)UploadImage。如果它们未包含在您的配置中,它们将被自动添加。

类似于Trix字段,您可以在字段定义上链式调用方法 withFiles,同时传入应存储图像的文件系统磁盘名称。

use Waynestate\Nova\CKEditor4Field\CKEditor;

CKEditor::make('Body')->withFiles('public');

为了修剪存储和表中任何过期的附件,您需要注册一个 作业 以定期运行。

use Waynestate\Nova\CKEditor4Field\Jobs\PruneStaleAttachments;

/**
* Define the application's command schedule.
*
* @param  \Illuminate\Console\Scheduling\Schedule  $schedule
* @return void
*/
protected function schedule(Schedule $schedule)
{
    $schedule->call(function () {
        (new PruneStaleAttachments)();
    })->daily();
}

使用文件上传的限制

当从编辑器中移除图像时,图像不会从文件系统中移除。目前您需要自行纠正这个问题。

自定义CKEditor实例

如果您不希望使用CKEditor CDN中的CKEditor,您可以将 config/nova/ckeditor-field.php 下的 ckeditor_url 修改为指向您希望使用的CKEditor的URL。

如果您想使用Composer来实现自定义CKEditor实例,请按照 使用Composer实现自定义CKEditor实例 的步骤进行。

Nova v1、v2或v3兼容性

如果您需要在Nova v1、v2或v3中使用 nova-ckeditor4-field,您可以安装版本 0.7.0

composer require waynestate/nova-ckeditor4-field:"^0.7.0"

变更日志

有关最近更改的更多信息,请参阅 CHANGELOG

贡献

有关详细信息,请参阅 CONTRIBUTING

安全

如果您发现任何安全相关的问题,请通过电子邮件 web@wayne.edu 联系我们,而不是使用问题跟踪器。

鸣谢

许可证

MIT许可证(MIT)。有关更多信息,请参阅 许可证文件