Failure when WYSIWYG and Toolbar Selection are Misconfigured

Created on 28 April 2023, over 1 year ago
Updated 15 February 2024, 11 months ago

Problem/Motivation

When either CKEditor or CKEditor5 is being used for HTML fields, there is potential for misconfigurations and failures if the selected editor and toolbar in the Patternkit JSON Library Settings are not in alignment.

Missing modules

These errors may be encountered if the Patternkit WYSIWYG editor setting is configured to use an editor without the supporting module enabled.

If the Patternkit setting for WYSIWYG editor is set to CKEditor5, but the CKEditor 5 module is not enabled, the user will encounter a WSOD with the following error:

Error: Class "Drupal\ckeditor5\Plugin\Editor\CKEditor5" not found in Drupal\patternkit\Plugin\PatternLibrary\PatternLibraryJSON->schemaEditor() (line 159 of modules/custom/patternkit/src/JSONSchemaEditorTrait.php).

If instead the Patternkit setting for WYSIWYG editor is set to CKEditor, but the CKEditor module is not enabled, the user will encounter a WSOD with the following error:

Error: Class "Drupal\ckeditor\Plugin\Editor\CKEditor" not found in Drupal\patternkit\Plugin\PatternLibrary\PatternLibraryJSON->schemaEditor() (line 162 of modules/custom/patternkit/src/JSONSchemaEditorTrait.php).

Misconfiguration

These errors may be encountered if the Patternkit WYSIWYG editor setting is configured to a CKEditor version that does not match the editor configured on the selected format.

If Patternkit is configured to use CKEditor 4, but the selected format uses CKEditor 5, the following warnings will be logged and the editor will load without any available buttons as shown in the screenshot below:

Warning: Undefined array key "rows" in Drupal\ckeditor\CKEditorPluginManager::getEnabledButtons() (line 124 of core/modules/ckeditor/src/CKEditorPluginManager.php).

Warning: foreach() argument must be of type array|object, null given in Drupal\ckeditor\CKEditorPluginManager::getEnabledButtons() (line 124 of core/modules/ckeditor/src/CKEditorPluginManager.php).

If Patternkit is configured to use CKEditor 5, but the selected format uses CKEditor 4, the user will encounter a WSOD or a failed AJAX request for editing the block with the following error logged:

TypeError: array_intersect(): Argument #1 ($array) must be of type array, null given in array_intersect() (line 203 of core/modules/ckeditor5/src/Plugin/CKEditor5PluginManager.php).

Proposed resolution

Work added from 🐛 Error: Class "Drupal\ckeditor5\Plugin\Editor\CKEditor5" not found Fixed should help mitigate this issue by adding validation and improved configuration limitation of configuration options on the related Patternkit admin form. In most cases, this will prevent users from encountering these issues. Some scenarios may still exist, however, especially while a site is being migrated from CKEditor4 to CKEditor5, where these issues may be naturally encountered.

Near-term, error handling should be added to prevent attempting to load classes that don't exist solely based on the configured editor option. Longer term, it would be nice to remove the configuration options for WYSIWYG and toolbar altogether in favor of using Drupal core's solution for selecting a format and attaching whatever editor is configured.

Remaining tasks

User interface changes

API changes

Data model changes

🐛 Bug report
Status

Fixed

Version

9.1

Component

Schema Editor

Created by

🇺🇸United States slucero Arkansas

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

Production build 0.71.5 2024