You are here

public function CKEditorPluginManager::getEnabledPluginFiles in Drupal 9

Same name and namespace in other branches
  1. 8 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.

1 call to CKEditorPluginManager::getEnabledPluginFiles()
CKEditorPluginManager::getCssFiles in core/modules/ckeditor/src/CKEditorPluginManager.php
Retrieves enabled plugins' iframe instance CSS files, keyed by plugin ID.

File

core/modules/ckeditor/src/CKEditorPluginManager.php, line 69

Class

CKEditorPluginManager
Provides a CKEditor Plugin plugin manager.

Namespace

Drupal\ckeditor

Code

public function getEnabledPluginFiles(Editor $editor, $include_internal_plugins = FALSE) {
  $plugins = array_keys($this
    ->getDefinitions());
  $toolbar_buttons = $this
    ->getEnabledButtons($editor);
  $enabled_plugins = [];
  $additional_plugins = [];
  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;
}