Replacing Entity Embed with Drupal Core Media Embed
As we work to upgrade the Spire Energy website to Drupal 10 we have run into challenges with a lack of support with some third-party modules. As part of the upgrade path, we must upgrade the built-in CKEditor 4 to CKEditor 5. However, currently, the Entity Embed module does not support either CKEditor 5 nor Drupal 10 yet. There is an open support ticket for this which offers a patch.
Given that we use the Entity Embed Module extensively in the content on Spire Energy, we needed an upgrade path that fully supports the upgraded editor and the next major version of Drupal. And we wanted to do this in the best-supported way that helps us maintain best practices. Before this, the entity embeds did not render in the WYSIWYG.
Since the advent of Drupal 8.8, it has been possible to embed Drupal Core Media Entities in your WYSIWYG text edit boxes. The core media entities enjoy the greatest level of support now and in the future and have rapidly become the go-to standard. It is also the best practice to divest ourselves of third-party modules in favor of core solutions where practical and possible.
Luckily with entity embeds, the practical solution is rather simple. The module simply embeds a “drupal-entity” tag in the text of your editor. By modifying this to read “drupal-media” with no changes to attributes it fully functions out of the box.
To affect these changes to all saved WYSIWYG data, we turned to the ”Convert Entity Embed to Media Embed” module. However, out of the box, this module did not support the “text_long” data type, of which all of our WYSIWYG fields are set to. Thus we apply the patch (which we fixed) found here to fully implement the needed functionality.
By installing this patched module on each environment and running the Drupal cron operation (often 2 or 3 times), all of your “drupal-entity” tags will get converted and you will be ready for the future.
Immediately after processing the full queue of tags, all of the existing content now renders in the WYSIWYG editor using CKEditor 5. We are now ready to continue on our Drupal 10 upgrade path.