Problem/Motivation
Currently, this module uses CustomConfig::getConfig() to override CKEditor settings. There are two issue with this:
- Certain settings are set by CKEditor's internal plugin and require a core patch to modify (#3052938: CKEditor should allow plugins to override default config)
If issue #1 is fixed, then
- Settings from plugins that load after CKEditor will be able to override custom configuration; however, by design, CKEditor config should have the final say.
Proposed resolution
In CustomConfig::getConfig(), instead of overriding settings, store them in their own setting for later:
// Convert numeric values to integers.
if (is_numeric($exploded_value[1])) {
$exploded_value[1] = (int) $exploded_value[1];
}
+ $config['ckeditor_custom_config'][$exploded_value[0]] = $exploded_value[1];
- $config[$exploded_value[0]] = $exploded_value[1];
}
}
Then in ckeditor_config.module, add
/**
* Implements hook_editor_js_settings_alter().
*/
function ckeditor_config_editor_js_settings_alter(array &$settings) {
foreach($settings['editor']['formats'] as $editor_name => &$editor) {
if (isset($editor['editorSettings']['ckeditor_custom_config'])) {
foreach ($editor['editorSettings']['ckeditor_custom_config'] as $name => $value) {
$editor['editorSettings'][$name] = $value;
}
}
}
}
Remaining tasks
Write patch
Verify tests
User interface changes
None.
API changes
None.
Data model changes
I don't believe so. We're not changing how config data is stored. The manipulations proposed here all happen at runtime.
Release notes snippet
Beginning in 8.x-2.1, CKEditor settings are now added using hook_editor_js_settings_alter(), which means they are added after all CKEditor Drupal plugins have provided their settings. This guarantees that settings defined by CKEditor config override settings provided by CKEditor Drupal plugins. Previously, this was not the case, specifically with regard to core's Internal plugin. The following settings can now be managed with CKEditor config without the use of a core patch:
- pasteFromWordPromptCleanup
- resize_dir
- justifyClasses
- entities
- disableNativeSpellChecker
Original report by TwoD
This architectural change to CKEditor config was originally raised by TwoD on #3052938: CKEditor should allow plugins to override default config.
| Comment | File | Size | Author |
|---|---|---|---|
| #2 | ckeditor_config-use_core_alter-3090970-2.patch | 7.7 KB | chris burge |
Comments
Comment #2
chris burge commentedPatch is attached.
This patch bypasses the core bug: #3052938: CKEditor should allow plugins to override default config. As a result, the documentation has been updated.
In tests, we're now rending an add node page with a CKEditor-enabled field. Then we're parsing the Drupal settings that are output as JSON. This tests everything from config entry through render, which is improved test coverage. We no longer compare values from CustomConfig::getConfig().
Comment #4
chris burge commented