Problem/Motivation

Currently, this module uses CustomConfig::getConfig() to override CKEditor settings. There are two issue with this:

  1. 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

  1. 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.

Comments

Chris Burge created an issue. See original summary.

chris burge’s picture

Assigned: Unassigned » chris burge
Issue summary: View changes
Status: Active » Needs review
StatusFileSize
new7.7 KB

Patch 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().

  • Chris Burge authored b228891 on 8.x-2.x
    Issue #3090970 by Chris Burge: Implement settings with...
chris burge’s picture

Assigned: chris burge » Unassigned
Issue summary: View changes
Status: Needs review » Fixed

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.