Coder Social home page Coder Social logo

nova-ckeditor4-field's Introduction

Laravel Nova CKEditor 4 Field

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

⚠️ CKEditor4 End of Life ⚠️

The time has come where CKEditor4 has reached it's semi End of Life, which you can read more about at CKEditor 4: End of Life June 2023

Unforunately to use the CKEditor4 LTS (anything greater than v4.22.1), it requires that you have a Long Term Support.

This package isn't going anywhere soon, but if you are using CKEditor4 v4.22.1 or less, you may encounter a Security Warning due to the CKEditor checking a version file on the CKEditor side.

This disables the security warning option by default within the configuration since by default it points to v4.22.1 non-LTS CKEditor4.

If you do have the LTS package for CKEditor4, please renable your version check within your configuration, before updating this package to v1.4.0.

Overview

This nova package allows you to use CKEditor 4 for text areas using Nova v4.

CKEditor Form Field

Installation

Nova v1, v2, v3 compatibility instructions

You can install the package into a Laravel application that uses Nova via composer:

composer require waynestate/nova-ckeditor4-field

By default the CKEditor 4 instance used is the latest (4.22.1) Full All version (https://cdn.ckeditor.com/). If you wish to use a different CKEditor 4 you can do so by publishing and editing the configuration.

Usage

<?php

namespace App\Nova;

use Waynestate\Nova\CKEditor4Field\CKEditor;

class Article extends Resource
{
    // ...

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

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

Overriding Config Values

To change any of config values, publish a config file:

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

Customization

Configuration options

You can change the configuration options of the CKEditor instance by either editing the published config file at nova.ckeditor-field.options

    /*
    |--------------------------------------------------------------------------------
    | CKEditor Options
    |--------------------------------------------------------------------------------
    |
    | To view a list of all available options checkout the CKEditor API documentation
    | https://ckeditor.com/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']
        ]
    ],

or you can pass it with the options method using:

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

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

        // ...
    ];
}

File Uploads

The nova-ckeditor4-field allows the use of file uploads by extending the attachment functionality of the Trix field

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

The package migrations will automatically run when running php artisan migrate.

If you are not going to use the Files and have no need for the migrations, you can disable migrations in config/nova/ckeditor-field.php, set the enable_migrations to false.

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

If you do not wish to use the Laravel Migration, but publish the migration yourself to your project. Within the published /config/nova/ckeditor-field.php, set the auto_migrate to false.

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

and then publish the migration to your project.

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

if you wish to not use the default Attachment and/or PendingAttachment models. You could replace with your own within the published /config/nova/ckeditor-field.php,

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

Using the File Uploads feature requires that the CKEditor uses the plugins Enhanced Image (image2) and UploadImage. If they are not included within your configuration, they will be added automatically.

Like the Trix field you'll be able to chain the method withFiles onto the field's definition, while passing the name of the filesystem disk where the images should be stored:

use Waynestate\Nova\CKEditor4Field\CKEditor;

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

Also to prune any stale attachments from the storage and table, you'll want to register a job to run periodically:

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

Limitations using File Uploads

Images are not removed from the filesystem when they are removed from the editor. For the time being you'll need to rectrify this on your own.

Custom CKEditor Instance

If you wish to not use the CKEditor from the CKEditor CDN, you can change the ckeditor_url under config/nova/ckeditor-field.php to point to the URL of the CKEditor you wish to use.

If you wish to go the route of a Custom CKEditor Instance using Composer then follow the steps at Using Composer for Custom CKEditor Instance

Nova v1, v2, or v3 compatibility

If you require the use of nova-ckeditor4-field using Nova v1, v2 or v3, you can install using version 0.7.0

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

Changelog

Please see CHANGELOG for more information on what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Security

If you discover any security related issues, please email [email protected] instead of using the issue tracker.

Credits

License

The MIT License (MIT). Please see License File for more information.

nova-ckeditor4-field's People

Contributors

adriandmitroca avatar chrispelzer avatar dsampaolo avatar f-liva avatar harrymessenger avatar robertvrabel avatar shaffe-fr avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

nova-ckeditor4-field's Issues

Version 1

Does there happen to be a road map with an estimated time-frame for when an actual version 1.0 will be released?

What about setting CKEDITOR.dtd ?

I am about solved question on this page

Editor strips <i> tag
I tried this

CKEditor::make('text')->options([
                'allowedContent' => true,
                'extraAllowedContent' => 'i;u;style;span;ul;li;table;td;style;*[id];*(*);*{*}',
                'coreStyles_italic' => [
                    'element' => 'i',
                    'overrides' => 'em'
                ],
                'removeButtons' => 'Cut,Copy,Paste,Undo,Redo,Anchor',
            ])

but it does not work

How to add the image2 as an Additional plugins in this package?

Hello!

I'm working with Nova 4 and integrated this package as an editor in one of my post modules.

Now, I need to integrate the below upload image plugin in CKeditor 👍

https://ckeditor.com/cke4/addon/image2

I've followed this solution but didn't get the upload option in image pop up

https://github.com/waynestate/nova-ckeditor4-field/wiki/Adding-additional-plugins

can anyone please guide me on this?

@chrispelzer @robertvrabel @f-liva @dsampaolo @shaffe-fr @harrymessenger

help() option does not work

It seems as if the help() method does not work on CKEditor

CKEditor::make('Survey Instructions', 'survey_instructions') ->help('These instructions will be printed as the first page of the survey'),

Number::make('Price', 'price') ->help('Enter price in US Dollars'),

The help appears in the second case, does not appear in the first case

Open a modal

It is possible to add a custom button that opens a modal?

Thx

Toolbar - List style

I did not find the option in the package to handle lists such as "style". I want to delete the h1 tag. Thank you

Possible to add codesnippet

Thanks for this helpful package. I just need to ask, if it there is a quick way to add CKEditor plugin for codesnippet.

Content edited in Source view not saving.

Edits from 'Source' are not working. Only edits made in the WYSIWYG editor are persisted. If you edit the source and then make changes in the WYSIWYG, it saves as expected.

Steps to reproduce the behavior:

  1. Click Source Button
  2. Change content
  3. Save Nova Resource

Expected behavior
Save content

Desktop (please complete the following information):

  • OS: Mac
  • Browser: Chrome
  • Version: 116.0.5845.187

Define the publishing groupings better for configs and migrations to make sure it's publish when needed

Change the grouping from config to be nova-ckeditor4-field-config
https://github.com/waynestate/nova-ckeditor4-field/blob/main/src/CKEditorFieldServiceProvider.php#L25-L27

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

Otherwise if someone was to do the following, it will publish the config inadvertently, which we allow config to be an opt in approach. Same goes with the migrations upcoming nova-ckeditor4-field-migrations

php artisan vendor:publish --tag=config

Configuring toolbar in config and on field can cause toolbar duplication

There appears to be an issue with merging of config options and passed options on a specific field, resulting in duplicated toolbar items.

To Reproduce

  1. Install package, leaving config as is.
  2. Add field via the CKEditor::make() method to a given Nova resource
  3. Using the field's options() method, apply toolbar modifications
CKEditor::make('Some Field')
    ->options([
        'toolbar' => [
            ['Source', '-', 'Print', '-', 'Cut', 'Copy', 'Paste', 'PasteText', 'PasteFromWord', ],
            ['Undo', 'Redo', '-', 'Find', 'Replace', '-', 'SelectAll', 'RemoveFormat'],
            ['HorizontalRule', 'SpecialChar'],
            '/',
            ['Format', ],
            ['Bold', 'Italic', 'Strike', '-', 'Subscript', 'Superscript'],
            ['NumberedList', 'BulletedList', '-', 'Outdent', 'Indent', 'Blockquote', ],
            ['JustifyLeft', 'JustifyCenter', 'JustifyRight'],
            ['Link', 'Unlink'],
            ['Maximize', 'ShowBlocks'],
        ],
    ])
  1. View the create/edit page for the Nova resource, and see the duplicated toolbar items (screenshots below)

Expected behavior
The toolbar should be overridden by the options passed at the field level

Screenshots
Actual
Screenshot 2023-04-06 at 3 30 26 PM

Expected
Screenshot 2023-04-06 at 3 30 52 PM

The issue appears to be related to the array_merge_recursive within the options() method on the field:

public function options($options)
{
    $currentOptions = $this->meta['options'] ?? [];

    return $this->withMeta([
        'options' => array_merge_recursive($currentOptions, $options),
    ]);
}

Calling array_merge_recursive on the entirety of the options array causes the duplication issue within the non-associative toolbar option. I don't think array_merge_recursive is necessarily wrong, but a special case is needed for the toolbar option and any other non-associative options.

Generic recursive merge example:

$merged = array_merge_recursive(['somekey' => [1, 2, 3]], ['somekey' => [1, 2, 3]])
// results in ['somekey' => [1,2,3,1,2,3]]

Plugins Support

Not really an issue as more of a question looking for instruction. I was wondering does your package support official CKEditor 4 plugins? Thanks!

Mathjax plugin

Hi, I am not able to activate the mathjax plugin.

I tried in 2 different ways:

  1. With Adding additional plugins wiki. Here i wasn't able to find the npm package, so i downloaded and copied the plugin directly to the public/js/vendor folder, once I finished all the steps, i got the following error:

Screenshot 2022-11-04 at 19 25 36

The documentation says that the mathjaxlib config wasn't set, which leads me to try to implement it as indicated in the ckeditor documentation (way 2)

  1. Simply added the following parameters to the configuration:
'options' => [
        // ....
        'extraPlugins' => 'mathjax',
        'mathJaxLib' => 'https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.4/MathJax.js?config=TeX-AMS_HTML',
        'mathJaxClass' => 'ik-equation',
    ],

In this case the plugin is properly fetched from the cdn

Screenshot 2022-11-04 at 19 39 03

There is no error in the console. I can explore the CKEDITOR object and see that the plugin is there.

Screenshot 2022-11-04 at 19 20 49

But unfortunately no widget is added to the component.

Could you help me to understand what i am doing wrong?

Many thanks in advance

Determine if uploadURL and filebrowserUploadURL which takes precent and will fall back to the other if not available.

It seems there is a certain order on which uploadURL takes precedent, need to take a closer look and determine the properly CKEditor api setting for displaying the Upload tab within Image2 dialog and properly uploading behavior as if it was drag and dropped on the editor.


As for the Upload button, I did look into that and as of right now the only supported option for uploading is by Drag and Dropping since the filebrowserUploadURL isn't configured.

Though it seems that there are some fallbacks in place, where if one isn't set then it uses the other, but I think the current set is that the final chain of the process. I'll look a little more into this.

Originally posted by @chrispelzer in #80 (comment)

Additional plugins ?

Hi,
first, thanks for the package !

This is a question but can't find the tag to make it so :
Is there a way to add other plugins ?

Would like to add this one for example : https://ckeditor.com/cke4/addon/wordcount but don't know in which folder to place the files ? it's supposed to go to "ckeditor/plugins/"

Photo credit or description

Is it possible to add a text (like credit or description) to an image?

It should be displayed as shown below;

Image showing photo credit

Drag/Drop options to enable/disable

Add option in config file or an ->dragAndDrop(true|false) to the field

Discussed in #77

Originally posted by bocanhcam February 9, 2023
Just a question:
How to disable drag/drop file and base64 images?
Thanks for help !!!

Migrations doesnt check for exisiting table

Describe the bug
I dont publish the migration cause of flexibility. You are using the publish command. The migrations will be executed on each deployment which is failing after the first deployment because the tables are already there.

Am i missing something?

To Reproduce
Steps to reproduce the behavior:

  1. Install package
  2. Deploy package (a deployment is a complete new checkout and composer install)
  3. Deploy package again

Expected behavior
Deploying the application should not break.

I guess the problem is the new checkout on every deployment. The application does not know about the migrations in the Deployment before.
Is there any possibility to disable package migrations if i publish them to my migration folder?

Load actual CKEditor 4 field default configuration file options

If installing the CKEditor4 field, but never publishing the configuration. The toolbar that is used is not the default configuration toolbar that, it is a more expanded toolbar. Though if you try to save anything, it will prevent saving. A plugin being loaded is causing issues but I am unable to pin point which one.

The editor is not initialized on fields with the same name

By declaring two fields with the same label but with different identifiers, CKEditor is instantiated using the label instead of the identifier, thus generating console errors and not loading the editor at the second instance.

public function fields(Request $request)
{
    return [
        CKEditor::make('Field Name', 'field_1'),
        CKEditor::make('Field Name', 'field_2'),
    ];
}

Opening console you can see this error:

The editor instance "Field Name" is already attached to the provided element.

And the second editor was not loaded.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.