class Editor

Same name in this branch
  1. main core/modules/editor/src/Attribute/Editor.php \Drupal\editor\Attribute\Editor
  2. main core/modules/editor/src/Annotation/Editor.php \Drupal\editor\Annotation\Editor
Same name and namespace in other branches
  1. 11.x core/modules/editor/src/Attribute/Editor.php \Drupal\editor\Attribute\Editor
  2. 11.x core/modules/editor/src/Entity/Editor.php \Drupal\editor\Entity\Editor
  3. 11.x core/modules/editor/src/Annotation/Editor.php \Drupal\editor\Annotation\Editor
  4. 10 core/modules/editor/src/Attribute/Editor.php \Drupal\editor\Attribute\Editor
  5. 10 core/modules/editor/src/Entity/Editor.php \Drupal\editor\Entity\Editor
  6. 10 core/modules/editor/src/Annotation/Editor.php \Drupal\editor\Annotation\Editor
  7. 9 core/modules/quickedit/src/Plugin/InPlaceEditor/Editor.php \Drupal\quickedit\Plugin\InPlaceEditor\Editor
  8. 9 core/modules/editor/src/Entity/Editor.php \Drupal\editor\Entity\Editor
  9. 9 core/modules/editor/src/Annotation/Editor.php \Drupal\editor\Annotation\Editor
  10. 9 core/modules/editor/src/Plugin/InPlaceEditor/Editor.php \Drupal\editor\Plugin\InPlaceEditor\Editor
  11. 8.9.x core/modules/editor/src/Entity/Editor.php \Drupal\editor\Entity\Editor
  12. 8.9.x core/modules/editor/src/Annotation/Editor.php \Drupal\editor\Annotation\Editor
  13. 8.9.x core/modules/editor/src/Plugin/InPlaceEditor/Editor.php \Drupal\editor\Plugin\InPlaceEditor\Editor

Defines the configured text editor entity.

An Editor entity is created when a filter format entity (Text format) is saved after selecting an editor plugin (eg: CKEditor). The ID of the Editor entity will be same as the ID of the filter format entity in which the editor plugin was selected.

Attributes

#[ConfigEntityType(id: 'editor', label: new TranslatableMarkup('Text editor'), label_collection: new TranslatableMarkup('Text editors'), label_singular: new TranslatableMarkup('text editor'), label_plural: new TranslatableMarkup('text editors'), entity_keys: [ 'id' => 'format', ], handlers: [ 'access' => EditorAccessControlHandler::class, ], label_count: [ 'singular' => '@count text editor', 'plural' => '@count text editors', ], constraints: [ 'RequiredConfigDependencies' => [ 'entityTypes' => [ 'filter_format', ], ], ], config_export: [ 'format', 'editor', 'settings', 'image_upload', ])]

Hierarchy

Expanded class hierarchy of Editor

64 files declare their use of Editor
AddedStylesheetsTest.php in core/modules/ckeditor5/tests/src/Functional/AddedStylesheetsTest.php
AddItemToToolbarConfigActionTest.php in core/modules/ckeditor5/tests/src/Kernel/ConfigAction/AddItemToToolbarConfigActionTest.php
AddListPluginStylesTest.php in core/modules/ckeditor5/tests/src/Functional/Update/AddListPluginStylesTest.php
CKEditor5.php in core/modules/ckeditor5/src/Plugin/Editor/CKEditor5.php
ckeditor5.post_update.php in core/modules/ckeditor5/ckeditor5.post_update.php
Post update functions for CKEditor 5.

... See full list

51 string references to 'Editor'
AssetAggregationAcrossPagesTest::testFrontAndRecipesPagesEditor in core/profiles/demo_umami/tests/src/FunctionalJavascript/AssetAggregationAcrossPagesTest.php
Checks the front and recipe page asset requests as an editor.
CKEditor5::assessActiveTextEditorAfterBuild in core/modules/ckeditor5/src/Plugin/Editor/CKEditor5.php
Form #after_build callback: provides text editor state changes.
CKEditor5::buildConfigurationForm in core/modules/ckeditor5/src/Plugin/Editor/CKEditor5.php
Form constructor.
CKEditor5::submitConfigurationForm in core/modules/ckeditor5/src/Plugin/Editor/CKEditor5.php
Form submission handler.
CKEditor5::validateConfigurationForm in core/modules/ckeditor5/src/Plugin/Editor/CKEditor5.php
Form validation handler.

... See full list

File

core/modules/editor/src/Entity/Editor.php, line 21

Namespace

Drupal\editor\Entity
View source
class Editor extends ConfigEntityBase implements EditorInterface {
  
  /**
   * Machine name of the text format for this configured text editor.
   *
   * @var string
   *
   * @see getFilterFormat()
   */
  protected $format;
  
  /**
   * The name (plugin ID) of the text editor.
   *
   * @var string
   */
  protected $editor;
  
  /**
   * The structured array of text editor plugin-specific settings.
   *
   * @var array
   */
  protected $settings = [];
  
  /**
   * The structured array of image upload settings.
   *
   * @var array
   */
  protected $image_upload = [];
  
  /**
   * The filter format this text editor is associated with.
   *
   * @var \Drupal\filter\FilterFormatInterface
   */
  protected $filterFormat;
  
  /**
   * @var \Drupal\Component\Plugin\PluginManagerInterface
   */
  protected $editorPluginManager;
  
  /**
   * {@inheritdoc}
   */
  public function id() {
    return $this->format;
  }
  
  /**
   * {@inheritdoc}
   */
  public function __construct(array $values, $entity_type) {
    parent::__construct($values, $entity_type);
    try {
      $plugin = $this->editorPluginManager()
        ->createInstance($this->editor);
      $this->settings += $plugin->getDefaultSettings();
    } catch (PluginNotFoundException) {
      // When a Text Editor plugin has gone missing, still allow the Editor
      // config entity to be constructed. The only difference is that default
      // settings are not added.
    }
  }
  
  /**
   * {@inheritdoc}
   */
  public function label() {
    return $this->getFilterFormat()
      ->label();
  }
  
  /**
   * {@inheritdoc}
   */
  public function calculateDependencies() {
    parent::calculateDependencies();
    // Create a dependency on the associated FilterFormat.
    $text_format = $this->getFilterFormat();
    if ($text_format) {
      $this->addDependency('config', $text_format->getConfigDependencyName());
    }
    else {
      trigger_error("The editor {$this->id()} is configured for text format {$this->id()} which does not exist. Review whether it is still needed and delete if not.", E_USER_WARNING);
    }
    // @todo use EntityWithPluginCollectionInterface so configuration between
    //   config entity and dependency on provider is managed automatically.
    $definition = $this->editorPluginManager()
      ->createInstance($this->editor)
      ->getPluginDefinition();
    $this->addDependency('module', $definition['provider']);
    return $this;
  }
  
  /**
   * {@inheritdoc}
   */
  public function hasAssociatedFilterFormat() {
    return $this->format !== NULL;
  }
  
  /**
   * {@inheritdoc}
   */
  public function getFilterFormat() {
    if (!$this->filterFormat) {
      $this->filterFormat = \Drupal::entityTypeManager()->getStorage('filter_format')
        ->load($this->format);
    }
    return $this->filterFormat;
  }
  
  /**
   * Returns the editor plugin manager.
   *
   * @return \Drupal\Component\Plugin\PluginManagerInterface
   *   The editor plugin manager instance.
   */
  protected function editorPluginManager() {
    if (!$this->editorPluginManager) {
      $this->editorPluginManager = \Drupal::service('plugin.manager.editor');
    }
    return $this->editorPluginManager;
  }
  
  /**
   * {@inheritdoc}
   */
  public function getEditor() {
    return $this->editor;
  }
  
  /**
   * {@inheritdoc}
   */
  public function setEditor($editor) {
    $this->editor = $editor;
    return $this;
  }
  
  /**
   * {@inheritdoc}
   */
  public function getSettings() {
    return $this->settings;
  }
  
  /**
   * {@inheritdoc}
   */
  public function setSettings(array $settings) {
    $this->settings = $settings;
    return $this;
  }
  
  /**
   * {@inheritdoc}
   */
  public function getImageUploadSettings() {
    return $this->image_upload;
  }
  
  /**
   * {@inheritdoc}
   */
  public function setImageUploadSettings(array $image_upload_settings) {
    $this->image_upload = $image_upload_settings;
    return $this;
  }
  
  /**
   * Computes all valid choices for the "image_upload.scheme" setting.
   *
   * @see editor.schema.yml
   *
   * @return string[]
   *   All valid choices.
   *
   * @internal
   */
  public static function getValidStreamWrappers() : array {
    return array_keys(\Drupal::service('stream_wrapper_manager')->getNames(StreamWrapperInterface::WRITE_VISIBLE));
  }

}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.