function _ckeditor_get_enabled_plugins
Gets all enabled CKEditor 4 plugins.
@internal
Parameters
\Drupal\editor\EditorInterface $editor: A text editor config entity configured to use CKEditor 4.
Return value
string[] The enabled CKEditor 4 plugin IDs.
3 calls to _ckeditor_get_enabled_plugins()
- CKEditor::submitConfigurationForm in core/
modules/ ckeditor/ src/ Plugin/ Editor/ CKEditor.php - Form submission handler.
- ckeditor_editor_presave in core/
modules/ ckeditor/ ckeditor.module - Implements hook_ENTITY_TYPE_presave().
- ckeditor_post_update_omit_settings_for_disabled_plugins in core/
modules/ ckeditor/ ckeditor.post_update.php - Updates Text Editors using CKEditor 4 to omit settings for disabled plugins.
File
-
core/
modules/ ckeditor/ ckeditor.module, line 139
Code
function _ckeditor_get_enabled_plugins(EditorInterface $editor) : array {
assert($editor->getEditor() === 'ckeditor');
$cke4_plugin_manager = \Drupal::service('plugin.manager.ckeditor.plugin');
// This is largely copied from the CKEditor 4 plugin manager, because it
// unfortunately does not provide the API this needs.
// @see \Drupal\ckeditor\CKEditorPluginManager::getEnabledPluginFiles()
$plugins = array_keys($cke4_plugin_manager->getDefinitions());
$toolbar_buttons = $cke4_plugin_manager->getEnabledButtons($editor);
$enabled_plugins = [];
$additional_plugins = [];
foreach ($plugins as $plugin_id) {
$plugin = $cke4_plugin_manager->createInstance($plugin_id);
$enabled = FALSE;
// Plugin is enabled if it provides a button that has been enabled.
if ($plugin instanceof CKEditorPluginButtonsInterface) {
$plugin_buttons = array_keys($plugin->getButtons());
$enabled = count(array_intersect($toolbar_buttons, $plugin_buttons)) > 0;
}
// Otherwise plugin is enabled if it declares itself as enabled.
if (!$enabled && $plugin instanceof CKEditorPluginContextualInterface) {
$enabled = $plugin->isEnabled($editor);
}
if ($enabled) {
$enabled_plugins[$plugin_id] = $plugin_id;
// Check if this plugin has dependencies that should be considered
// enabled.
$additional_plugins = array_merge($additional_plugins, array_diff($plugin->getDependencies($editor), $additional_plugins));
}
}
// Add the list of dependent plugins.
foreach ($additional_plugins as $plugin_id) {
$enabled_plugins[$plugin_id] = $plugin_id;
}
return $enabled_plugins;
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.