class CKEditorPluginManager

CKEditor Plugin manager.

Hierarchy

Expanded class hierarchy of CKEditorPluginManager

1 file declares its use of CKEditorPluginManager
CKEditorPluginManagerTest.php in drupal/core/modules/ckeditor/lib/Drupal/ckeditor/Tests/CKEditorPluginManagerTest.php
Definition of \Drupal\ckeditor\Tests\CKEditorPluginManagerTest.
1 string reference to 'CKEditorPluginManager'
ckeditor.services.yml in drupal/core/modules/ckeditor/ckeditor.services.yml
drupal/core/modules/ckeditor/ckeditor.services.yml
1 service uses CKEditorPluginManager

File

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

Namespace

Drupal\ckeditor
View source
class CKEditorPluginManager extends PluginManagerBase {

  /**
   * Overrides \Drupal\Component\Plugin\PluginManagerBase::__construct().
   *
   * @param \Traversable $namespaces
   *   An object that implements \Traversable which contains the root paths
   *   keyed by the corresponding namespace to look for plugin implementations,
   */
  public function __construct(\Traversable $namespaces) {
    $annotation_namespaces = array(
      'Drupal\\ckeditor\\Annotation' => $namespaces['Drupal\\ckeditor'],
    );
    $this->discovery = new AnnotatedClassDiscovery('CKEditorPlugin', $namespaces, $annotation_namespaces, 'Drupal\\ckeditor\\Annotation\\CKEditorPlugin');
    $this->discovery = new AlterDecorator($this->discovery, 'ckeditor_plugin_info');
    $this->discovery = new CacheDecorator($this->discovery, 'ckeditor_plugin');
    $this->factory = new DefaultFactory($this->discovery);
  }

  /**
   * 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.
   *
   * @param \Drupal\editor\Plugin\Core\Entity\Editor $editor
   *   A configured text editor object.
   * @param bool $include_internal_plugins
   *   Defaults to FALSE. When set to TRUE, plugins whose isInternal() method
   *   returns TRUE will also be included.
   * @return 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.
   */
  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;
  }

  /**
   * Retrieves all plugins that implement CKEditorPluginButtonsInterface.
   *
   * @param \Drupal\editor\Plugin\Core\Entity\Editor $editor
   *   A configured text editor object.
   * @return array
   *   A list of the CKEditor plugins that implement buttons, with the plugin
   *   IDs as keys and lists of button metadata (as implemented by getButtons())
   *   as values.
   *
   * @see CKEditorPluginButtonsInterface::getButtons()
   */
  public function getButtonsPlugins(Editor $editor) {
    $plugins = array_keys($this
      ->getDefinitions());
    $buttons_plugins = array();
    foreach ($plugins as $plugin_id) {
      $plugin = $this
        ->createInstance($plugin_id);
      if ($plugin instanceof CKEditorPluginButtonsInterface) {
        $buttons_plugins[$plugin_id] = $plugin
          ->getButtons();
      }
    }
    return $buttons_plugins;
  }

  /**
   * Injects the CKEditor plugins settings forms as a vertical tabs subform.
   *
   * @param array &$form
   *   A reference to an associative array containing the structure of the form.
   * @param array &$form_state
   *   A reference to a keyed array containing the current state of the form.
   * @param \Drupal\editor\Plugin\Core\Entity\Editor $editor
   *   A configured text editor object.
   */
  public function injectPluginSettingsForm(array &$form, array &$form_state, Editor $editor) {
    $definitions = $this
      ->getDefinitions();
    foreach (array_keys($definitions) as $plugin_id) {
      $plugin = $this
        ->createInstance($plugin_id);
      if ($plugin instanceof CKEditorPluginConfigurableInterface) {
        $plugin_settings_form = array();
        $form['plugins'][$plugin_id] = array(
          '#type' => 'details',
          '#title' => $definitions[$plugin_id]['label'],
          '#group' => 'editor][settings][plugin_settings',
        );
        $form['plugins'][$plugin_id] += $plugin
          ->settingsForm($plugin_settings_form, $form_state, $editor);
      }
    }
  }

}

Members

Namesort descending Modifiers Type Description Overrides
CKEditorPluginManager::getButtonsPlugins public function Retrieves all plugins that implement CKEditorPluginButtonsInterface.
CKEditorPluginManager::getEnabledPlugins public function Determines which plug-ins are enabled.
CKEditorPluginManager::injectPluginSettingsForm public function Injects the CKEditor plugins settings forms as a vertical tabs subform.
CKEditorPluginManager::__construct public function Overrides \Drupal\Component\Plugin\PluginManagerBase::__construct().
PluginManagerBase::$defaults protected property A set of defaults to be referenced by $this->processDefinition() if additional processing of plugins is necessary or helpful for development purposes. 3
PluginManagerBase::$discovery protected property The object that discovers plugins managed by this manager.
PluginManagerBase::$factory protected property The object that instantiates plugins managed by this manager.
PluginManagerBase::$mapper protected property The object that returns the preconfigured plugin instance appropriate for a particular runtime condition.
PluginManagerBase::clearCachedDefinitions public function Clears static and persistent plugin definition caches. Overrides CachedDiscoveryInterface::clearCachedDefinitions
PluginManagerBase::createInstance public function Returns a preconfigured instance of a plugin. Overrides FactoryInterface::createInstance 6
PluginManagerBase::getDefinition public function Gets a specific plugin definition. Overrides DiscoveryInterface::getDefinition
PluginManagerBase::getDefinitions public function Gets the definition of all plugins for this type. Overrides DiscoveryInterface::getDefinitions
PluginManagerBase::getInstance public function Returns a preconfigured instance of a plugin. Overrides MapperInterface::getInstance 6
PluginManagerBase::processDefinition public function Performs extra processing on plugin definitions. 2