class Core
Provides the CKEditor 4 to 5 upgrade for Drupal core's CKEditor plugins.
@CKEditor4To5Upgrade( id = "core", cke4_buttons = { "DrupalImage", "DrupalLink", "DrupalUnlink", "Bold", "Italic", "Underline", "Superscript", "Subscript", "BulletedList", "NumberedList", "Outdent", "Indent", "Undo", "Redo", "Blockquote", "JustifyLeft", "JustifyCenter", "JustifyRight", "JustifyBlock", "HorizontalRule", "Format", "Table", "Source", "Strike", "Cut", "Copy", "Paste", "PasteText", "PasteFromWord", "ShowBlocks", "Maximize", "-", "RemoveFormat", "Styles", "SpecialChar", "Language", "DrupalMediaLibrary", }, cke4_plugin_settings = { "stylescombo", "language", }, cke5_plugin_elements_subset_configuration = { "ckeditor5_heading", "ckeditor5_alignment", "ckeditor5_list", "ckeditor5_style", "media_media", } )
@internal Plugin classes are internal.
Hierarchy
- class \Drupal\Component\Plugin\PluginBase implements \Drupal\Component\Plugin\PluginInspectionInterface, \Drupal\Component\Plugin\DerivativeInspectionInterface
- class \Drupal\Core\Plugin\PluginBase uses \Drupal\Core\StringTranslation\StringTranslationTrait, \Drupal\Core\DependencyInjection\DependencySerializationTrait, \Drupal\Core\Messenger\MessengerTrait extends \Drupal\Component\Plugin\PluginBase
- class \Drupal\ckeditor5\Plugin\CKEditor4To5Upgrade\Core implements \Drupal\ckeditor5\Plugin\CKEditor4To5UpgradePluginInterface extends \Drupal\Core\Plugin\PluginBase
 
 
 - class \Drupal\Core\Plugin\PluginBase uses \Drupal\Core\StringTranslation\StringTranslationTrait, \Drupal\Core\DependencyInjection\DependencySerializationTrait, \Drupal\Core\Messenger\MessengerTrait extends \Drupal\Component\Plugin\PluginBase
 
Expanded class hierarchy of Core
224 string references to 'Core'
- action.info.yml in core/
modules/ action/ action.info.yml  - core/modules/action/action.info.yml
 - action_form_ajax_test.info.yml in core/
modules/ action/ tests/ action_form_ajax_test/ action_form_ajax_test.info.yml  - core/modules/action/tests/action_form_ajax_test/action_form_ajax_test.info.yml
 - announcements_feed.info.yml in core/
modules/ announcements_feed/ announcements_feed.info.yml  - core/modules/announcements_feed/announcements_feed.info.yml
 - AssetResolverTest::testGetCssAssets in core/
tests/ Drupal/ Tests/ Core/ Asset/ AssetResolverTest.php  - @covers ::getCssAssets[[api-linebreak]] @dataProvider providerAttachedCssAssets
 - AssetResolverTest::testGetJsAssets in core/
tests/ Drupal/ Tests/ Core/ Asset/ AssetResolverTest.php  - @covers ::getJsAssets[[api-linebreak]] @dataProvider providerAttachedJsAssets
 
File
- 
              core/
modules/ ckeditor5/ src/ Plugin/ CKEditor4To5Upgrade/ Core.php, line 73  
Namespace
Drupal\ckeditor5\Plugin\CKEditor4To5UpgradeView source
class Core extends PluginBase implements CKEditor4To5UpgradePluginInterface {
  
  /**
   * {@inheritdoc}
   */
  public function mapCKEditor4ToolbarButtonToCKEditor5ToolbarItem(string $cke4_button, HTMLRestrictions $text_format_html_restrictions) : ?array {
    static $alignment_mapped;
    switch ($cke4_button) {
      // @see \Drupal\ckeditor\Plugin\CKEditorPlugin\DrupalImage
      case 'DrupalImage':
        return [
          'drupalInsertImage',
        ];
      // @see \Drupal\ckeditor\Plugin\CKEditorPlugin\DrupalLink
      case 'DrupalLink':
        return [
          'link',
        ];
      case 'DrupalUnlink':
        return NULL;
      // @see \Drupal\ckeditor\Plugin\CKEditorPlugin\Internal
      case 'Bold':
      case 'Italic':
      case 'Underline':
      case 'Superscript':
      case 'Subscript':
      case 'BulletedList':
      case 'NumberedList':
      case 'Outdent':
      case 'Indent':
      case 'Undo':
      case 'Redo':
        return [
          lcfirst($cke4_button),
        ];
      case 'Blockquote':
        return [
          'blockQuote',
        ];
      case 'JustifyLeft':
      case 'JustifyCenter':
      case 'JustifyRight':
      case 'JustifyBlock':
        if (!isset($alignment_mapped)) {
          $alignment_mapped = TRUE;
          return [
            'alignment',
          ];
        }
        return NULL;
      case 'HorizontalRule':
        return [
          'horizontalLine',
        ];
      case 'Format':
        if ($text_format_html_restrictions->isUnrestricted()) {
          // When no restrictions exist, all tags possibly supported by "Format"
          // in CKEditor 4 must be supported.
          return [
            'heading',
            'codeBlock',
          ];
        }
        $allowed_elements = $text_format_html_restrictions->getAllowedElements();
        // Check if <h*> is supported.
        // Merely checking the existence of the array key is sufficient; this
        // plugin does not set or need any additional attributes.
        // @see \Drupal\filter\Plugin\FilterInterface::getHTMLRestrictions()
        $intersect = array_intersect([
          'h2',
          'h3',
          'h4',
          'h5',
          'h6',
        ], array_keys($allowed_elements));
        // Do not return the 'codeBlock' toolbar item, not even when `<pre>` is
        // allowed in the text format. This ensures that SmartDefaultSettings:
        // - first adds the `code` toolbar item (for inline `<code>`)
        // - then adds `codeBlock` toolbar item (for code blocks: `<pre><code>`)
        // @see https://www.drupal.org/project/drupal/issues/3263384#comment-14446315
        return count($intersect) > 0 ? [
          'heading',
        ] : NULL;
      case 'Table':
        return [
          'insertTable',
        ];
      case 'Source':
        return [
          'sourceEditing',
        ];
      case 'Strike':
        return [
          'strikethrough',
        ];
      case 'Cut':
      case 'Copy':
      case 'Paste':
      case 'PasteText':
      case 'PasteFromWord':
      case 'Maximize':
      case '-':
        // @see https://www.drupal.org/project/ckeditor5/issues/3211049#comment-14167764
        return NULL;
      case 'ShowBlocks':
        return [
          'showBlocks',
        ];
      // @see \Drupal\ckeditor5\Plugin\CKEditor5Plugin\RemoveFormat
      case 'RemoveFormat':
        return [
          'removeFormat',
        ];
      // @see \Drupal\ckeditor\Plugin\CKEditorPlugin\StylesCombo
      case 'Styles':
        return [
          'style',
        ];
      // @see \Drupal\ckeditor5\Plugin\CKEditor5Plugin\specialCharacters
      case 'SpecialChar':
        return [
          'specialCharacters',
        ];
      // @see \Drupal\ckeditor\Plugin\CKEditorPlugin\Language
      case 'Language':
        return [
          'textPartLanguage',
        ];
      // @see \Drupal\media_library\Plugin\CKEditorPlugin\DrupalMediaLibrary
      case 'DrupalMediaLibrary':
        return [
          'drupalMedia',
        ];
      default:
        throw new \OutOfBoundsException();
    }
  }
  
  /**
   * {@inheritdoc}
   */
  public function mapCKEditor4SettingsToCKEditor5Configuration(string $cke4_plugin_id, array $cke4_plugin_settings) : ?array {
    switch ($cke4_plugin_id) {
      // @see \Drupal\ckeditor\Plugin\CKEditorPlugin\StylesCombo
      case 'stylescombo':
        if (!isset($cke4_plugin_settings['styles'])) {
          $styles = [];
        }
        else {
          [$styles] = Style::parseStylesFormValue($cke4_plugin_settings['styles']);
        }
        return [
          'ckeditor5_style' => [
            'styles' => $styles,
          ],
        ];
      // @see \Drupal\ckeditor\Plugin\CKEditorPlugin\Language
      case 'language':
        // Identical configuration.
        return [
          'ckeditor5_language' => $cke4_plugin_settings,
        ];
      default:
        throw new \OutOfBoundsException();
    }
  }
  
  /**
   * {@inheritdoc}
   */
  public function computeCKEditor5PluginSubsetConfiguration(string $cke5_plugin_id, FilterFormatInterface $text_format) : ?array {
    switch ($cke5_plugin_id) {
      case 'ckeditor5_heading':
        $restrictions = $text_format->getHtmlRestrictions();
        if ($restrictions === FALSE) {
          // The default is to allow all headings, which makes sense when there
          // are no restrictions.
          // @see \Drupal\ckeditor5\Plugin\CKEditor5Plugin\Heading::DEFAULT_CONFIGURATION
          return NULL;
        }
        // Otherwise, only enable headings that allowed by the restrictions.
        $configuration = [];
        foreach (range(1, 6) as $index) {
          // Merely checking the existence of the array key is sufficient; this
          // plugin does not set or need any additional attributes.
          // @see \Drupal\filter\Plugin\FilterInterface::getHTMLRestrictions()
          if (array_key_exists("h{$index}", $restrictions['allowed'])) {
            $configuration['enabled_headings'][] = "heading{$index}";
          }
        }
        return $configuration;
      case 'ckeditor5_alignment':
        $alignment_classes_to_types = [
          'text-align-left' => 'left',
          'text-align-right' => 'right',
          'text-align-center' => 'center',
          'text-align-justify' => 'justify',
        ];
        $restrictions = $text_format->getHtmlRestrictions();
        if ($restrictions === FALSE) {
          // The default is to allow all alignments. This makes sense when there
          // are no restrictions.
          // @see \Drupal\ckeditor5\Plugin\CKEditor5Plugin\Alignment::DEFAULT_CONFIGURATION
          return NULL;
        }
        // Otherwise, enable alignment types based on the provided restrictions.
        // I.e. if a tag is found with a text-align-{alignment type} class,
        // activate that alignment type.
        $configuration = [];
        foreach ($restrictions['allowed'] as $tag) {
          $classes = isset($tag['class']) && is_array($tag['class']) ? $tag['class'] : [];
          foreach (array_keys($classes) as $class) {
            if (isset($alignment_classes_to_types[$class])) {
              $configuration['enabled_alignments'][] = $alignment_classes_to_types[$class];
            }
          }
        }
        if (isset($configuration['enabled_alignments'])) {
          $configuration['enabled_alignments'] = array_unique($configuration['enabled_alignments']);
        }
        return $configuration;
      case 'ckeditor5_list':
        $restrictions = $text_format->getHtmlRestrictions();
        if ($restrictions === FALSE) {
          // The default is to allow a reversed list and a start index, which makes sense when there
          // are no restrictions.
          // @see \Drupal\ckeditor5\Plugin\CKEditor5Plugin\ListPlugin::default_configuration()
          return NULL;
        }
        $configuration = [];
        $configuration['properties']['reversed'] = !empty($restrictions['allowed']['ol']['reversed']);
        $configuration['properties']['startIndex'] = !empty($restrictions['allowed']['ol']['start']);
        return $configuration;
      case 'media_media':
        $restrictions = $text_format->getHtmlRestrictions();
        if ($restrictions === FALSE) {
          // The default is to not allow the user to override the default view mode.
          // @see \Drupal\ckeditor5\Plugin\CKEditor5Plugin\Media::defaultConfiguration()
          return NULL;
        }
        $configuration = [];
        // Check if data-view-mode is allowed.
        $configuration['allow_view_mode_override'] = !empty($restrictions['allowed']['drupal-media']['data-view-mode']);
        return $configuration;
      case 'ckeditor5_style':
        // @see mapCKEditor4SettingsToCKEditor5Configuration()
        return NULL;
      default:
        throw new \OutOfBoundsException();
    }
  }
}
Members
| Title Sort descending | Modifiers | Object type | Summary | Overriden Title | Overrides | 
|---|---|---|---|---|---|
| Core::computeCKEditor5PluginSubsetConfiguration | public | function | Computes elements subset configuration for CKEditor 5 plugin. | Overrides CKEditor4To5UpgradePluginInterface::computeCKEditor5PluginSubsetConfiguration | |
| Core::mapCKEditor4SettingsToCKEditor5Configuration | public | function | Maps CKEditor 4 settings to the CKEditor 5 equivalent, if needed. | Overrides CKEditor4To5UpgradePluginInterface::mapCKEditor4SettingsToCKEditor5Configuration | |
| Core::mapCKEditor4ToolbarButtonToCKEditor5ToolbarItem | public | function | Maps a CKEditor 4 button to the CKEditor 5 equivalent, if it exists. | Overrides CKEditor4To5UpgradePluginInterface::mapCKEditor4ToolbarButtonToCKEditor5ToolbarItem | |
| 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. | ||
| PluginBase::__construct | public | function | Constructs a \Drupal\Component\Plugin\PluginBase object. | 86 | |
| 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.