Verified Commit 2f71a477 authored by Lauri Timmanee's avatar Lauri Timmanee
Browse files

Issue #3381557 by nmangold, lauriii, Wim Leers, joshuami: [DrupalMedia]...

Issue #3381557 by nmangold, lauriii, Wim Leers, joshuami: [DrupalMedia] Formatting lost when attempting to edit media within a list item in CKEditor 5
parent 10c903f1
Loading
Loading
Loading
Loading
Loading
+1 −1

File changed.

Preview size limit exceeded, changes collapsed.

+1 −4
Original line number Diff line number Diff line
@@ -207,10 +207,7 @@ export default class DrupalMediaEditing extends Plugin {
  _defineSchema() {
    const schema = this.editor.model.schema;
    schema.register('drupalMedia', {
      allowWhere: '$block',
      isObject: true,
      isContent: true,
      isBlock: true,
      inheritAllFrom: '$blockObject',
      allowAttributes: Object.keys(this.attrs),
    });
    // Register `<drupal-media>` as a block element in the DOM converter. This
+1 −1
Original line number Diff line number Diff line
@@ -86,7 +86,7 @@ export default class InsertDrupalMediaCommand extends Command {
    }

    this.editor.model.change((writer) => {
      this.editor.model.insertContent(
      this.editor.model.insertObject(
        createDrupalMedia(writer, modelAttributes),
      );
    });
+58 −0
Original line number Diff line number Diff line
@@ -275,6 +275,64 @@ public function testOnlyDrupalMediaTagProcessed() {
    $assert_session->elementExists('css', '.ck-widget.drupal-media');
  }

  /**
   * Tests adding media to a list does not split the list.
   */
  public function testMediaSplitList() {
    $assert_session = $this->assertSession();

    $editor = Editor::load('test_format');
    $settings = $editor->getSettings();

    // Add lists to the editor.
    $settings['plugins']['ckeditor5_list'] = [
      'reversed' => FALSE,
      'startIndex' => FALSE,
    ];
    $settings['toolbar']['items'] = array_merge($settings['toolbar']['items'], ['bulletedList', 'numberedList']);
    $editor->setSettings($settings);
    $editor->save();

    // Add lists to the filter.
    $filter_format = $editor->getFilterFormat();
    $filter_format->setFilterConfig('filter_html', [
      'status' => TRUE,
      'settings' => [
        'allowed_html' => '<p> <br> <strong> <em> <a href> <drupal-media data-entity-type data-entity-uuid data-align data-caption alt data-view-mode> <ol> <ul> <li>',
      ],
    ]);
    $filter_format->save();

    $this->assertSame([], array_map(
      function (ConstraintViolation $v) {
        return (string) $v->getMessage();
      },
      iterator_to_array(CKEditor5::validatePair(
        Editor::load('test_format'),
        FilterFormat::load('test_format')
      ))
    ));

    // Wrap the media with a list item.
    $original_value = $this->host->body->value;
    $this->host->body->value = '<ol><li>' . $original_value . '</li></ol>';
    $this->host->save();
    $this->drupalGet($this->host->toUrl('edit-form'));

    $this->assertNotEmpty($upcasted_media = $assert_session->waitForElementVisible('css', '.ck-widget.drupal-media'));

    // Confirm the media is wrapped by the list item on the editing view.
    $assert_session->elementExists('css', 'li > .drupal-media');
    // Confirm the media is not adjacent to the list on the editing view.
    $assert_session->elementNotExists('css', 'ol + .drupal-media');

    $editor_dom = new \DOMXPath($this->getEditorDataAsDom());
    // Confirm drupal-media is wrapped by the list item.
    $this->assertNotEmpty($editor_dom->query('//li/drupal-media'));
    // Confirm the media is not adjacent to the list.
    $this->assertEmpty($editor_dom->query('//ol/following-sibling::drupal-media'));
  }

  /**
   * Tests that arbitrary attributes are allowed via GHS.
   */