Commit d401ef11 authored by Ben Mullins's avatar Ben Mullins
Browse files

Issue #3247683 by Wim Leers, lauriii, bnjmnm, Reinmar: Disable CKEditor 5's...

Issue #3247683 by Wim Leers, lauriii, bnjmnm, Reinmar: Disable CKEditor 5's automatic link decorators (in Drupal filters should be used instead)
parent 835ccb98
Loading
Loading
Loading
Loading
+1 −1

File changed.

Preview size limit exceeded, changes collapsed.

+7 −0
Original line number Diff line number Diff line
@@ -352,6 +352,13 @@ export default class DrupalLinkMediaEditing extends Plugin {
    editor.conversion.for('dataDowncast').add(dataDowncastMediaLink());

    this._enableManualDecorators();

    const linkCommand = editor.commands.get('link');
    if (linkCommand.automaticDecorators.length > 0) {
      throw new Error(
        'The Drupal Media plugin is not compatible with automatic link decorators. To use Drupal Media, disable any plugins providing automatic link decorators.',
      );
    }
  }

  /**
+21 −0
Original line number Diff line number Diff line
@@ -90,6 +90,27 @@ private static function validateCKEditor5Aspects(string $id, array $definition):
    if (!isset($definition['ckeditor5']['plugins'])) {
      throw new InvalidPluginDefinitionException($id, sprintf('The "%s" CKEditor 5 plugin definition must contain a "ckeditor5.plugins" key.', $id));
    }

    // Automatic link decorators make sense in CKEditor 5, where the generated
    // HTML must be assumed to be served as-is. But it does not make sense in
    // in Drupal, where we prefer not storing (hardcoding) such decisions in the
    // database. Drupal instead filters it on output, using the filter system.
    if (isset($definition['ckeditor5']['config']['link'])) {
      // @see https://ckeditor.com/docs/ckeditor5/latest/api/module_link_link-LinkDecoratorAutomaticDefinition.html
      if (isset($definition['ckeditor5']['config']['link']['decorators']) && is_array($definition['ckeditor5']['config']['link']['decorators'])) {
        foreach ($definition['ckeditor5']['config']['link']['decorators'] as $decorator) {
          if ($decorator['mode'] === 'automatic') {
            throw new InvalidPluginDefinitionException($id, sprintf('The "%s" CKEditor 5 plugin definition specifies an automatic decorator, this is not supported. Use the Drupal filter system instead.', $id));
          }
        }
      }
      // CKEditor 5 offers one preconfigured automatic link decorator under a
      // special config flag.
      // @see https://ckeditor.com/docs/ckeditor5/latest/api/module_link_link-LinkConfig.html#member-addTargetToExternalLinks
      if (isset($definition['ckeditor5']['config']['link']['addTargetToExternalLinks']) && $definition['ckeditor5']['config']['link']['addTargetToExternalLinks']) {
        throw new InvalidPluginDefinitionException($id, sprintf('The "%s" CKEditor 5 plugin definition specifies an automatic decorator, this is not supported. Use the Drupal filter system instead.', $id));
      }
    }
  }

  /**
+17 −0
Original line number Diff line number Diff line
ckeditor5_automatic_link_decorator_test_llamaClass:
  ckeditor5:
    plugins: []
    config:
      link:
        decorators:
          pinkColor:
            mode: 'automatic'
            attributes:
              class: 'llama'
  drupal:
    label: Links must have 'llama' class!
    elements:
      - <a class>
    conditions:
      plugins:
        - ckeditor5_link
+6 −0
Original line number Diff line number Diff line
name: CKEditor 5 Automatic Link Decorator Test
type: module
description: "Provides infrastructure for testing CKEditor 5 automatic link decorators."
package: Testing
dependencies:
  - ckeditor5:ckeditor5
Loading