public function CKEditorPluginManager::getEnabledPluginFiles in Zircon Profile 8
Same name and namespace in other branches
- 8.0 core/modules/ckeditor/src/CKEditorPluginManager.php \Drupal\ckeditor\CKEditorPluginManager::getEnabledPluginFiles()
Retrieves enabled plugins' files, keyed by plugin ID.
For CKEditor plugins that implement:
- CKEditorPluginButtonsInterface, not CKEditorPluginContextualInterface, a plugin is enabled if at least one of its buttons is in the toolbar;
- CKEditorPluginContextualInterface, not CKEditorPluginButtonsInterface, a plugin is enabled if its isEnabled() method returns TRUE
- both of these interfaces, a plugin is enabled if either is the case.
Internal plugins (those that are part of the bundled build of CKEditor) are excluded by default, since they are loaded implicitly. If you need to know even implicitly loaded (i.e. internal) plugins, then set the optional second parameter.
Parameters
\Drupal\editor\Entity\Editor $editor: A configured text editor object.
bool $include_internal_plugins: Defaults to FALSE. When set to TRUE, plugins whose isInternal() method returns TRUE will also be included.
Return value
array A list of the enabled CKEditor plugins, with the plugin IDs as keys and the Drupal root-relative plugin files as values. For internal plugins, the value is NULL.
File
- core/
modules/ ckeditor/ src/ CKEditorPluginManager.php, line 72 - Contains \Drupal\ckeditor\CKEditorPluginManager.
Class
- CKEditorPluginManager
- Provides a CKEditor Plugin plugin manager.
Namespace
Drupal\ckeditorCode
public function getEnabledPluginFiles(Editor $editor, $include_internal_plugins = FALSE) {
$plugins = array_keys($this
->getDefinitions());
// Flatten each row.
$toolbar_rows = array();
$settings = $editor
->getSettings();
foreach ($settings['toolbar']['rows'] as $row_number => $row) {
$toolbar_rows[] = array_reduce($settings['toolbar']['rows'][$row_number], function (&$result, $button_group) {
return array_merge($result, $button_group['items']);
}, array());
}
$toolbar_buttons = array_unique(NestedArray::mergeDeepArray($toolbar_rows));
$enabled_plugins = array();
$additional_plugins = array();
foreach ($plugins as $plugin_id) {
$plugin = $this
->createInstance($plugin_id);
if (!$include_internal_plugins && $plugin
->isInternal()) {
continue;
}
$enabled = FALSE;
// Enable this plugin 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 enable this plugin if it declares itself as enabled.
if (!$enabled && $plugin instanceof CKEditorPluginContextualInterface) {
$enabled = $plugin
->isEnabled($editor);
}
if ($enabled) {
$enabled_plugins[$plugin_id] = $plugin
->isInternal() ? NULL : $plugin
->getFile();
// Check if this plugin has dependencies that also need to be 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) {
$plugin = $this
->createInstance($plugin_id);
$enabled_plugins[$plugin_id] = $plugin
->isInternal() ? NULL : $plugin
->getFile();
}
// Always return plugins in the same order.
asort($enabled_plugins);
return $enabled_plugins;
}