class SourceEditing

Same name and namespace in other branches
  1. 11.x core/modules/ckeditor5/src/Plugin/CKEditor5Plugin/SourceEditing.php \Drupal\ckeditor5\Plugin\CKEditor5Plugin\SourceEditing
  2. 9 core/modules/ckeditor5/src/Plugin/CKEditor5Plugin/SourceEditing.php \Drupal\ckeditor5\Plugin\CKEditor5Plugin\SourceEditing

CKEditor 5 Source Editing plugin configuration.

@internal Plugin classes are internal.

Hierarchy

Expanded class hierarchy of SourceEditing

1 file declares its use of SourceEditing
SourceEditingPluginTest.php in core/modules/ckeditor5/tests/src/Unit/SourceEditingPluginTest.php
21 string references to 'SourceEditing'
ckeditor5.ckeditor5.yml in core/modules/ckeditor5/ckeditor5.ckeditor5.yml
core/modules/ckeditor5/ckeditor5.ckeditor5.yml
CKEditor5UpdateImageToolbarItemTest::test in core/modules/ckeditor5/tests/src/Functional/Update/CKEditor5UpdateImageToolbarItemTest.php
Tests that `uploadImage` toolbar item is updated to `drupalInsertImage`.
ckeditor5_post_update_image_toolbar_item in core/modules/ckeditor5/ckeditor5.post_update.php
The image toolbar item changed from `uploadImage` to `drupalInsertImage`.
Core::mapCKEditor4ToolbarButtonToCKEditor5ToolbarItem in core/modules/ckeditor5/src/Plugin/CKEditor4To5Upgrade/Core.php
Maps a CKEditor 4 button to the CKEditor 5 equivalent, if it exists.
editor.editor.basic_html.yml in core/profiles/standard/config/install/editor.editor.basic_html.yml
core/profiles/standard/config/install/editor.editor.basic_html.yml

... See full list

File

core/modules/ckeditor5/src/Plugin/CKEditor5Plugin/SourceEditing.php, line 21

Namespace

Drupal\ckeditor5\Plugin\CKEditor5Plugin
View source
class SourceEditing extends CKEditor5PluginDefault implements CKEditor5PluginConfigurableInterface, CKEditor5PluginElementsSubsetInterface {
  use CKEditor5PluginConfigurableTrait;
  
  /**
   * {@inheritdoc}
   */
  public function buildConfigurationForm(array $form, FormStateInterface $form_state) {
    $form['allowed_tags'] = [
      '#type' => 'textarea',
      '#title' => $this->t('Manually editable HTML tags'),
      '#default_value' => implode(' ', $this->configuration['allowed_tags']),
      '#description' => $this->t('A list of HTML tags that can be used while editing source. It is only necessary to add tags that are not already supported by other enabled plugins. For example, if "Bold" is enabled, it is not necessary to add the <code>&lt;strong&gt;</code> tag, but it may be necessary to add <code>&lt;dl&gt;&lt;dt&gt;&lt;dd&gt;</code> in a format that does not have a definition list plugin, but requires definition list markup.'),
    ];
    return $form;
  }
  
  /**
   * {@inheritdoc}
   */
  public function validateConfigurationForm(array &$form, FormStateInterface $form_state) {
    // Match the config schema structure at
    // ckeditor5.plugin.ckeditor5_sourceEditing.
    $form_value = $form_state->getValue('allowed_tags');
    assert(is_string($form_value));
    $config_value = HTMLRestrictions::fromString($form_value)->toCKEditor5ElementsArray();
    $form_state->setValue('allowed_tags', $config_value);
  }
  
  /**
   * {@inheritdoc}
   */
  public function submitConfigurationForm(array &$form, FormStateInterface $form_state) {
    $this->configuration['allowed_tags'] = $form_state->getValue('allowed_tags');
  }
  
  /**
   * {@inheritdoc}
   */
  public function defaultConfiguration() {
    return [
      'allowed_tags' => [],
    ];
  }
  
  /**
   * {@inheritdoc}
   */
  public function getElementsSubset() : array {
    // Drupal needs to know which plugin can create a particular <tag>, and not
    // just a particular attribute on a tag: <tag attr>.
    // SourceEditing enables every tag a plugin lists, even if it's only there
    // to add support for an attribute. So, compute a list of only the tags.
    // F.e.: <foo attr>, <bar>, <baz bar> would result in <foo>, <bar>, <baz>.
    $r = HTMLRestrictions::fromString(implode(' ', $this->configuration['allowed_tags']));
    $plain_tags = $r->extractPlainTagsSubset()
      ->toCKEditor5ElementsArray();
    // Return the union of the "tags only" list and the original configuration,
    // but omit duplicates (the entries that were already "tags only").
    // F.e.: merging the tags only list of <foo>, <bar>, <baz> with the original
    // list of <foo attr>, <bar>, <baz bar> would result in <bar> having a
    // duplicate.
    $subset = array_unique(array_merge($plain_tags, $this->configuration['allowed_tags']));
    return $subset;
  }
  
  /**
   * {@inheritdoc}
   */
  public function getDynamicPluginConfig(array $static_plugin_config, EditorInterface $editor) : array {
    $restrictions = HTMLRestrictions::fromString(implode(' ', $this->configuration['allowed_tags']));
    // Only handle concrete HTML elements to allow the Wildcard HTML support
    // plugin to handle wildcards.
    // @see \Drupal\ckeditor5\Plugin\CKEditor5PluginManager::getCKEditor5PluginConfig()
    $concrete_restrictions = $restrictions->getConcreteSubset();
    return [
      'htmlSupport' => [
        'allow' => $concrete_restrictions->toGeneralHtmlSupportConfig(),
        // Any manually created elements are explicitly allowed to be empty.
'allowEmpty' => array_keys($concrete_restrictions->getAllowedElements()),
      ],
    ];
  }

}

Members

Title Sort descending Modifiers Object type Summary Overriden Title Overrides
CKEditor5PluginConfigurableTrait::getConfiguration public function
CKEditor5PluginConfigurableTrait::setConfiguration public function
CKEditor5PluginDefault::__construct public function Constructs a \Drupal\Component\Plugin\PluginBase object. Overrides PluginBase::__construct 3
DependencySerializationTrait::$_entityStorages protected property An array of entity type IDs keyed by the property name of their storages.
DependencySerializationTrait::$_serviceIds protected property An array of service IDs keyed by property name used for serialization.
DependencySerializationTrait::__sleep public function 2
DependencySerializationTrait::__wakeup public function #[\ReturnTypeWillChange] 2
MessengerTrait::$messenger protected property The messenger. 25
MessengerTrait::messenger public function Gets the messenger. 25
MessengerTrait::setMessenger public function Sets the messenger.
PluginBase::$configuration protected property Configuration information passed into the plugin. 1
PluginBase::$pluginDefinition protected property The plugin implementation definition. 1
PluginBase::$pluginId protected property The plugin ID.
PluginBase::DERIVATIVE_SEPARATOR constant A string which is used to separate base plugin IDs from the derivative ID.
PluginBase::getBaseId public function Gets the base_plugin_id of the plugin instance. Overrides DerivativeInspectionInterface::getBaseId
PluginBase::getDerivativeId public function Gets the derivative_id of the plugin instance. Overrides DerivativeInspectionInterface::getDerivativeId
PluginBase::getPluginDefinition public function Gets the definition of the plugin implementation. Overrides PluginInspectionInterface::getPluginDefinition 2
PluginBase::getPluginId public function Gets the plugin ID of the plugin instance. Overrides PluginInspectionInterface::getPluginId
PluginBase::isConfigurable public function Determines if the plugin is configurable.
SourceEditing::buildConfigurationForm public function Form constructor. Overrides PluginFormInterface::buildConfigurationForm
SourceEditing::defaultConfiguration public function Gets default configuration for this plugin. Overrides ConfigurableInterface::defaultConfiguration
SourceEditing::getDynamicPluginConfig public function Allows a plugin to modify its static configuration. Overrides CKEditor5PluginDefault::getDynamicPluginConfig
SourceEditing::getElementsSubset public function Returns a configured subset of the elements supported by this plugin. Overrides CKEditor5PluginElementsSubsetInterface::getElementsSubset
SourceEditing::submitConfigurationForm public function Form submission handler. Overrides PluginFormInterface::submitConfigurationForm
SourceEditing::validateConfigurationForm public function Form validation handler. Overrides PluginFormInterface::validateConfigurationForm
StringTranslationTrait::$stringTranslation protected property The string translation service. 3
StringTranslationTrait::formatPlural protected function Formats a string containing a count of items.
StringTranslationTrait::getNumberOfPlurals protected function Returns the number of plurals supported by a given language.
StringTranslationTrait::getStringTranslation protected function Gets the string translation service.
StringTranslationTrait::setStringTranslation public function Sets the string translation service to use. 2
StringTranslationTrait::t protected function Translates a string to the current language or to a given language.

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