NOTE: This Plugin is not meant for actual use with Craft 5. The current release includes a script for migrating embeds to CKEditor with inline blocks.
This plugin requires Craft CMS 5 or later and the Craft Redactor and CKEditor plugins. The plugin is not actually working with current Craft CMS 5.0.
In order to migrate your embeds fields to CKEditor fields with inline blocks, do the following steps:
- Install the CKEditor plugin, if not done already
- Migrate all your Redactor fields to CKEditor fields and ignore the warnings about missing config settings for the embeds plugin
- Check your htmlpurifier config. Remove
"AutoFormat.RemoveEmpty": true,
, if given. This setting causes the purifier to remove Entry blocks from inside the CKEditor content. - Run
php craft gc/run
! The migration script might encounter errors if you don't. - In your local environment, run
php craft embeds/migrate-ckeditor [--copy-field=embedsCopy] [--embeds-field=embeds]
. This might take a while because the script handles every entry, draft and revision with these fields. Run this script for every combination of Embeds and Embeds Copy field that you have and note every one of those. - Adjust your rendering code to the new CKEditor field (See below).
- Commit and deploy the changes made to the project config. (It should at least add the
createEntry
Button to the CKEditor config) - Run the scripts from steps no. 4 and 5 in every other environment after deploying.
- You should now have CKEditor fields with your old embeds as inline blocks in the correct position inside the content.
- After everything is deployed, you can remove the old Embeds Matrix field and the Embeds plugin.
The mergeEmbeds()
function won't work anymore. And you'll eventually remove this plugin completely. So
rendering is up to you now. The following code example might help you as a starter:
# $field is your CKEditor field
$chunks = [];
foreach ($field->getChunks() as $chunk) {
if ($chunk instanceof craft\ckeditor\data\Markup) {
$chunks[] = [
'type' => "copy",
'html' => $chunk->getHtml(),
];
} else {
/** @var craft\ckeditor\data\Entry $chunk */
$embed = $chunk->getEntry();
$type = rtrim($embed->type->handle);
$embedData = $this->handleEmbed($embed); // This is where you handle your embeds
$chunks[] = [
'type' => $type,
'data' => $embedData,
];
}
}
return $chunks;
Another approach would be to switch to using Partials for rendering.

Brought to you by Fork Unstable Media GmbH