Issue #3268860 by lauriii, Wim Leers: Elements wrapping <drupal-media> are not retained
parent
99b6843db1
commit
f74006416e
File diff suppressed because one or more lines are too long
|
@ -93,6 +93,10 @@ export default class DrupalMediaEditing extends Plugin {
|
||||||
isBlock: true,
|
isBlock: true,
|
||||||
allowAttributes: Object.keys(this.attrs),
|
allowAttributes: Object.keys(this.attrs),
|
||||||
});
|
});
|
||||||
|
// Register `<drupal-media>` as a block element in the DOM converter. This
|
||||||
|
// ensures that the DOM converter knows to handle the `<drupal-media>` as a
|
||||||
|
// block element.
|
||||||
|
this.editor.editing.view.domConverter.blockElements.push('drupal-media');
|
||||||
}
|
}
|
||||||
|
|
||||||
_defineConverters() {
|
_defineConverters() {
|
||||||
|
|
|
@ -215,8 +215,10 @@ class MediaTest extends WebDriverTestBase {
|
||||||
$editor = Editor::load('test_format');
|
$editor = Editor::load('test_format');
|
||||||
$settings = $editor->getSettings();
|
$settings = $editor->getSettings();
|
||||||
|
|
||||||
// Allow the data-foo attribute in drupal-media via GHS.
|
// Allow the data-foo attribute in drupal-media via GHS. Also, add support
|
||||||
$settings['plugins']['ckeditor5_sourceEditing']['allowed_tags'] = ['<drupal-media data-foo>'];
|
// for div's with data-foo attribute to ensure that drupal-media elements
|
||||||
|
// can be wrapped with other block elements.
|
||||||
|
$settings['plugins']['ckeditor5_sourceEditing']['allowed_tags'] = ['<drupal-media data-foo>', '<div data-bar>'];
|
||||||
$editor->setSettings($settings);
|
$editor->setSettings($settings);
|
||||||
$editor->save();
|
$editor->save();
|
||||||
|
|
||||||
|
@ -224,7 +226,7 @@ class MediaTest extends WebDriverTestBase {
|
||||||
$filter_format->setFilterConfig('filter_html', [
|
$filter_format->setFilterConfig('filter_html', [
|
||||||
'status' => TRUE,
|
'status' => TRUE,
|
||||||
'settings' => [
|
'settings' => [
|
||||||
'allowed_html' => '<p> <br> <strong> <em> <a href> <drupal-media data-entity-type data-entity-uuid data-align data-caption alt data-foo>',
|
'allowed_html' => '<p> <br> <strong> <em> <a href> <drupal-media data-entity-type data-entity-uuid data-align data-caption alt data-foo> <div data-bar>',
|
||||||
],
|
],
|
||||||
]);
|
]);
|
||||||
$filter_format->save();
|
$filter_format->save();
|
||||||
|
@ -240,7 +242,7 @@ class MediaTest extends WebDriverTestBase {
|
||||||
|
|
||||||
// Add data-foo use to an existing drupal-media tag.
|
// Add data-foo use to an existing drupal-media tag.
|
||||||
$original_value = $this->host->body->value;
|
$original_value = $this->host->body->value;
|
||||||
$this->host->body->value = str_replace('drupal-media', 'drupal-media data-foo="bar" ', $original_value);
|
$this->host->body->value = '<div data-bar="baz">' . str_replace('drupal-media', 'drupal-media data-foo="bar" ', $original_value) . '</div>';
|
||||||
$this->host->save();
|
$this->host->save();
|
||||||
$this->drupalGet($this->host->toUrl('edit-form'));
|
$this->drupalGet($this->host->toUrl('edit-form'));
|
||||||
|
|
||||||
|
@ -250,8 +252,15 @@ class MediaTest extends WebDriverTestBase {
|
||||||
$this->assertNotEmpty($preview = $assert_session->waitForElementVisible('css', '.ck-widget.drupal-media > [data-drupal-media-preview="ready"] > .media', 30000));
|
$this->assertNotEmpty($preview = $assert_session->waitForElementVisible('css', '.ck-widget.drupal-media > [data-drupal-media-preview="ready"] > .media', 30000));
|
||||||
$this->assertEquals('bar', $preview->getAttribute('data-foo'));
|
$this->assertEquals('bar', $preview->getAttribute('data-foo'));
|
||||||
|
|
||||||
|
// Confirm that the media is wrapped by the div on the editing view.
|
||||||
|
$assert_session->elementExists('css', 'div[data-bar="baz"] > .drupal-media');
|
||||||
|
|
||||||
// Confirm data-foo is not stripped from source.
|
// Confirm data-foo is not stripped from source.
|
||||||
$this->assertSourceAttributeSame('data-foo', 'bar');
|
$this->assertSourceAttributeSame('data-foo', 'bar');
|
||||||
|
|
||||||
|
// Confirm that drupal-media is wrapped by the div.
|
||||||
|
$editor_dom = new \DOMXPath($this->getEditorDataAsDom());
|
||||||
|
$this->assertNotEmpty($editor_dom->query('//div[@data-bar="baz"]/drupal-media'));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in New Issue