class EditorManager

Configurable text editor manager.

Hierarchy

Expanded class hierarchy of EditorManager

2 files declare their use of EditorManager
CKEditorTest.php in drupal/core/modules/ckeditor/lib/Drupal/ckeditor/Tests/CKEditorTest.php
Definition of \Drupal\ckeditor\Tests\CKEditorTest.
EditorManagerTest.php in drupal/core/modules/editor/lib/Drupal/editor/Tests/EditorManagerTest.php
Definition of \Drupal\editor\Tests\EditorManagerTest.
1 string reference to 'EditorManager'
editor.services.yml in drupal/core/modules/editor/editor.services.yml
drupal/core/modules/editor/editor.services.yml
1 service uses EditorManager

File

drupal/core/modules/editor/lib/Drupal/editor/Plugin/EditorManager.php, line 20
Contains \Drupal\editor\Plugin\InPlaceEditorManager.

Namespace

Drupal\editor\Plugin
View source
class EditorManager 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\\editor\\Annotation' => $namespaces['Drupal\\editor'],
    );
    $this->discovery = new AnnotatedClassDiscovery('Editor', $namespaces, $annotation_namespaces, 'Drupal\\editor\\Annotation\\Editor');
    $this->discovery = new AlterDecorator($this->discovery, 'editor_info');
    $this->discovery = new CacheDecorator($this->discovery, 'editor');
    $this->factory = new DefaultFactory($this->discovery);
  }

  /**
   * Populates a key-value pair of available text editors.
   *
   * @return array
   *   An array of translated text editor labels, keyed by ID.
   */
  public function listOptions() {
    $options = array();
    foreach ($this
      ->getDefinitions() as $key => $definition) {
      $options[$key] = $definition['label'];
    }
    return $options;
  }

  /**
   * Retrieves text editor libraries and JavaScript settings.
   *
   * @param array $format_ids
   *   An array of format IDs as returned by array_keys(filter_formats()).
   *
   * @return array
   *   An array of attachments, for use with #attached.
   *
   * @see drupal_process_attached()
   */
  public function getAttachments(array $format_ids) {
    $attachments = array(
      'library' => array(),
    );
    $settings = array();
    foreach ($format_ids as $format_id) {
      $editor = editor_load($format_id);
      if (!$editor) {
        continue;
      }
      $plugin = $this
        ->createInstance($editor->editor);

      // Libraries.
      $attachments['library'] = array_merge($attachments['library'], $plugin
        ->getLibraries($editor));

      // JavaScript settings.
      $settings[$format_id] = array(
        'editor' => $editor->editor,
        'editorSettings' => $plugin
          ->getJSSettings($editor),
      );
    }

    // We have all JavaScript settings, allow other modules to alter them.
    drupal_alter('editor_js_settings', $settings);
    if (empty($attachments['library']) && empty($settings)) {
      return array();
    }
    $attachments['js'][] = array(
      'type' => 'setting',
      'data' => array(
        'editor' => array(
          'formats' => $settings,
        ),
      ),
    );
    return $attachments;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
EditorManager::getAttachments public function Retrieves text editor libraries and JavaScript settings.
EditorManager::listOptions public function Populates a key-value pair of available text editors.
EditorManager::__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