function ckeditor_editor_presave

Implements hook_ENTITY_TYPE_presave().

File

core/modules/ckeditor/ckeditor.module, line 266

Code

function ckeditor_editor_presave(EditorInterface $editor) {
    // Only try to update editors using CKEditor 4.
    if ($editor->getEditor() !== 'ckeditor') {
        return FALSE;
    }
    $enabled_plugins = _ckeditor_get_enabled_plugins($editor);
    // Only update if the editor has plugin settings for disabled plugins.
    $needs_update = FALSE;
    $settings = $editor->getSettings();
    // Updates are not needed if plugin settings are not defined for the editor.
    if (!isset($settings['plugins'])) {
        return;
    }
    foreach (array_keys($settings['plugins']) as $plugin_id) {
        if (!in_array($plugin_id, $enabled_plugins, TRUE)) {
            unset($settings['plugins'][$plugin_id]);
            $needs_update = TRUE;
        }
    }
    if ($needs_update) {
        $editor->setSettings($settings);
    }
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.