public function CKEditorPluginManager::getEnabledPlugins

Determines which plug-ins are enabled.

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\Plugin\Core\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

drupal/core/modules/ckeditor/lib/Drupal/ckeditor/CKEditorPluginManager.php, line 64
Contains \Drupal\ckeditor\CKEditorPluginManager.

Class

CKEditorPluginManager
CKEditor Plugin manager.

Namespace

Drupal\ckeditor

Code

public function getEnabledPlugins(Editor $editor, $include_internal_plugins = FALSE) {
  $plugins = array_keys($this
    ->getDefinitions());
  $toolbar_buttons = array_unique(NestedArray::mergeDeepArray($editor->settings['toolbar']['buttons']));
  $enabled_plugins = array();
  foreach ($plugins as $plugin_id) {
    $plugin = $this
      ->createInstance($plugin_id);
    if (!$include_internal_plugins && $plugin
      ->isInternal()) {
      continue;
    }
    $enabled = FALSE;
    if ($plugin instanceof CKEditorPluginButtonsInterface) {
      $plugin_buttons = array_keys($plugin
        ->getButtons());
      $enabled = count(array_intersect($toolbar_buttons, $plugin_buttons)) > 0;
    }
    if (!$enabled && $plugin instanceof CKEditorPluginContextualInterface) {
      $enabled = $plugin
        ->isEnabled($editor);
    }
    if ($enabled) {
      $enabled_plugins[$plugin_id] = $plugin
        ->isInternal() ? NULL : $plugin
        ->getFile();
    }
  }

  // Always return plugins in the same order.
  asort($enabled_plugins);
  return $enabled_plugins;
}