1

There seemed to be a plugin that did exactly what I need: https://ckeditor.com/cke4/addon/simplebutton

But first it is for CKEditor 4, but I am using Craft 5 and therefore CKEditor 5.

So my questions are:

  • How can I add plugins to CKEditor 5 within craft
  • Is there a CKEditor 5 alternative for this?

Edit: I found this link: https://github.com/craftcms/ckeditor?tab=readme-ov-file#adding-ckeditor-plugins And it should be telling me how to install a plugin.

In my case I have found this plugin (CKEditor 5 Styles) but still the instructions are very cryptic how I should install it.

I understand that, because it is a first-party package, that there is alreads a build

The next instruction

Once the CKEditor package is in place in your Craft plugin, create an asset bundle which extends BaseCkeditorPackageAsset

is alot less clear.

  1. How do I know that the plugin is in place? I have done nothing so far, I just know that craft 5 already installs ckeditor 5...
  2. "create an asset bundle". Well there is an example but I find it difficult to translate to my case.

All other instructions that follow are also unclear. Maybe somebody can help me a little bit with this. I think it is probably rather basic if you know yii and so forth, but to me the whole project structure and the logic how those things go together is a mystery :).

0

1 Answer 1

2

Is there a CKEditor 5 alternative for this?

I'm not an expert in CKEditor, so I can't help specifically with the alternative for Simple-Button plugin, I tried to recreate it in CKEditor 5, but the changes from version 4 to 5 were too significant, and I wasn't able to successfully recreate it. However, I can explain how to install a new plugin in CKEditor for Craft CMS.

Note: These steps assume that you already have knowledge about Craft CMS asset bundle. If you are unfamiliar with asset bundle, please refer to the Craft CMS Asset Bundle documentation to learn how to create and manage modules in Craft.

Steps to Install a CKEditor Plugin in Craft CMS

Once the CKEditor package is in place in your Craft plugin, create an asset bundle that extends BaseCkeditorPackageAsset.

I believe this means that if you already have the DLL build package from your plugin (in this case, for Simple-Button), you can create an asset bundle in your module that extends BaseCkeditorPackageAsset.

1. Creating the DLL build plugin

You can start by creating the DLL build of your plugin. You have two options:

  1. Use an existing package from CKEditor. You can explore available packages here.
  2. Build your own plugin from scratch using the CKEditor package generator.

To use an existing package, run the following command to get the zip version of the selected package: npm pack @ckeditor/{the-package-from-the-list}@41.0.0

After extracting the zip file, you won't need to run npm run dll:build since the DLL build file is already created in build/package-name.js. This package-name.js file is your DLL build and can be used in Craft CMS’s asset bundle.

2. Create the asset bundle

Next, create an asset bundle that extends BaseCkeditorPackageAsset and include the DLL file in its asset folder. Here’s an example using the ckeditor5-special-characters package:

    class CkeditorCustomizationAsset extends BaseCkeditorPackageAsset
    {
        public $sourcePath = __DIR__ . '/dist'; // Path to the DLL build
        public $depends = [];

        public $css = [];

        public $js = [
            'special-characters.js' // The DLL file
        ];

        public array $pluginNames = [ // these names came from the DLL file, you can search 'pluginName' for the available options
            'SpecialCharacters',
            'SpecialCharactersEssentials'
        ];

        public array $toolbarItems = [ // this toolbar came from the DLL file, you can search 'componentFactory.add()' for the available options
            'specialCharacters'
        ];


    }

folder structure based on above code

yourModule/
│
├── assetbundles/
│   └── ckeditorcustomization/
│       ├── dist/
│       │   └── special-characters.js
│       └── CkeditorCustomizationAsset.php
│
└── Module.php

Now you have assetbundle with DLL build, you just need to register this assetbundle into CKEditor.

3. Registering Package into CKEditor

Finally, register the package in CKEditor by adding this code in the init() function of your module:

\craft\ckeditor\Plugin::registerCkeditorPackage(CkeditorCustomizationAsset::class);


This should integrate your CKEditor plugin into Craft CMS.

All the step is based on Craft Quest's Customizing CKEditor in Craft CMS 5

1
  • Thank you a lot. In the end I also followed the Craft Quest tutorial. And then I realised that I did not have to install that plugin, as I could get the desired behaviour with rendering a link (a tag) instead of a button. Apart from that I had problems installing the style plugin because the tutorial and your indication were not clear where I would find the pluginName. Maybe I was not searching thoroughly for "pluginName", but yeah anyway thanks a lot, although I did not need it :)
    – Merc
    Commented Nov 3 at 10:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.