Skip to content

Conversation

@brianjhanson
Copy link
Contributor

@brianjhanson brianjhanson commented Feb 7, 2025

Updates CKEditor to use the new installation methods. The big change between old and new is that the new no longer supports DDLs and leans all in to JavaScript imports and import maps.

Updating Plugins

For the most part, plugin authors should follow the instructions in the migrating custom plugins documentation from CKEditor.

On the Craft side, the updates aren't too involved.

  • Classes extending BaseCkeditorPackageAsset must now include a $namespace property that will be the module for the import statement generated. It can technically be almost anything, but using a @{author}/ckeditor5-{handle} format is recommended.
  • Add the main entry point to your Plugin::registerCkeditorPackage() call so we can properly format the import statement for your plugin.
public function init()
{
    parent::init();

    if (Craft::$app->getRequest()->getIsCpRequest()) {
        Plugin::registerCkeditorPackage(MyAssetBundle::class, 'index.js')
    }
}
  • Make sure to update your AssetBundle to be included as a module
public $js = [
-    'index.js',
+.   ['index.js', 'type' => 'module']
]

The full AssetBundle class will look something like:

<?php

namespace modules\site\web\assets\ckeditorplugin;

use Craft;
use craft\ckeditor\web\assets\BaseCkeditorPackageAsset;
use craft\ckeditor\web\assets\ckeditor\CkeditorAsset;
use craft\web\AssetBundle;

/**
 * Ckeditor Plugin asset bundle
 */
class CkeditorPluginAsset extends BaseCkeditorPackageAsset
{
    public $sourcePath = __DIR__ . '/dist';

    public string $namespace = '@craftcms/ckeditor5-test';

    public $js = [
        ['index.js', 'type' => 'module']
    ];

    public array $pluginNames = ['Test'];
    public array$toolbarItems = ['test'];
}

First Party plugins

If all you want to do is add a first party plugin (like ImageResize we've added a CkeditorConfig::registerFirstPartyPackage() method you can call from your plugin or module's init method.

use craft\ckeditor\helpers\CkeditorConfig;

CkeditorConfig::registerFirstPartyPackage(['SpecialCharacters', 'SpecialCharactersEssentials'], ['specialCharacters']);
CkeditorConfig::registerFirstPartyPackage(['ImageResize']);

Extra plugins will be included into the ckeditor5 JavaScript import statement.

Browser Support

Because the new installation methods rely on importmaps this plugin includes a shim for older browsers that may not support them.

Related Issues

PT-1916

@brianjhanson brianjhanson force-pushed the feature/update-installation-method branch from 95cadf1 to 347af19 Compare February 18, 2025 19:53
@brianjhanson brianjhanson marked this pull request as ready for review February 24, 2025 19:35
@i-just i-just mentioned this pull request Feb 28, 2025
4 tasks
@brandonkelly brandonkelly merged commit bc0f055 into 5.x Apr 12, 2025
6 checks passed
@brandonkelly brandonkelly deleted the feature/update-installation-method branch April 12, 2025 13:27
@brianjhanson
Copy link
Contributor Author

Related issues/discussions for when 5.0 is released

#201 (reply in thread)
#362
#328
#101

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants