Skip to content
Snippets Groups Projects
Commit d9b11354 authored by Richard Porter's avatar Richard Porter Committed by Marcos Cano
Browse files

Issue #3098733 by richardbporter, firass.ziedan, dasginganinja, gngn, Oscaner,...

Issue #3098733 by richardbporter, firass.ziedan, dasginganinja, gngn, Oscaner, drupal-son, marcoscano, John Cook: Fatal error after saving the page not have a reuse entity
parent b68beca1
No related branches found
No related tags found
No related merge requests found
......@@ -24,6 +24,13 @@ class CkeditorImage extends TextFieldEmbedBase {
$xpath = new \DOMXPath($dom);
$entities = [];
foreach ($xpath->query('//img[@data-entity-type and @data-entity-uuid]') as $node) {
// Skip elements with empty data-entity-uuid/type attributes.
if (empty($node->getAttribute('data-entity-uuid'))
|| empty($node->getAttribute('data-entity-type'))
) {
continue;
}
// Note that this does not cover 100% of the situations. In the (unlikely
// but possible) use case where the user embeds the same entity twice in
// the same field, we are just recording 1 usage for this target entity,
......
......@@ -24,6 +24,12 @@ class EntityEmbed extends TextFieldEmbedBase {
$xpath = new \DOMXPath($dom);
$entities = [];
foreach ($xpath->query('//drupal-entity[@data-entity-type and @data-entity-uuid]') as $node) {
// Skip elements with empty data-entity-uuid/type attributes.
if (empty($node->getAttribute('data-entity-uuid'))
|| empty($node->getAttribute('data-entity-type'))
) {
continue;
}
// Note that this does not cover 100% of the situations. In the (unlikely
// but possible) use case where the user embeds the same entity twice in
// the same field, we are just recording 1 usage for this target entity,
......
......@@ -24,6 +24,13 @@ class LinkIt extends TextFieldEmbedBase {
$xpath = new \DOMXPath($dom);
$entities = [];
foreach ($xpath->query('//a[@data-entity-type and @data-entity-uuid]') as $node) {
// Skip elements with empty data-entity-uuid/type attributes.
if (empty($node->getAttribute('data-entity-uuid'))
|| empty($node->getAttribute('data-entity-type'))
) {
continue;
}
// Note that this does not cover 100% of the situations. In the (unlikely
// but possible) use case where the user embeds the same entity twice in
// the same field, we are just recording 1 usage for this target entity,
......
......@@ -24,6 +24,10 @@ class MediaEmbed extends TextFieldEmbedBase {
$xpath = new \DOMXPath($dom);
$entities = [];
foreach ($xpath->query('//drupal-media[@data-entity-type="media" and @data-entity-uuid]') as $node) {
// Skip elements with empty data-entity-uuid attributes.
if (empty($node->getAttribute('data-entity-uuid'))) {
continue;
}
// Note that this does not cover 100% of the situations. In the (unlikely
// but possible) use case where the user embeds the same entity twice in
// the same field, we are just recording 1 usage for this target entity,
......
......@@ -112,6 +112,27 @@ class EmbeddedContentTest extends EntityUsageJavascriptTestBase {
$this->assertEquals($expected, $usage);
}
/**
* Tests the Entity Embed plugin parsing does not error with malformed HTML.
*/
public function testEntityEmbedWithMalformedHtml() {
$embedded_text = '<drupal-entity data-embed-button="node" data-entity-embed-display="entity_reference:entity_reference_label" data-entity-embed-display-settings="{&quot;link&quot;:1}" data-entity-type="" data-entity-uuid=""></drupal-entity>';
$node = Node::create([
'type' => 'eu_test_ct',
'title' => 'This is a node with malformed EntityEmbed HTML',
'field_eu_test_rich_text' => [
'value' => $embedded_text,
'format' => 'eu_test_text_format',
],
]);
$node->save();
$this->drupalGet('/node/' . $node->id());
$this->assertSession()->pageTextContains('This is a node with malformed EntityEmbed HTML');
}
/**
* Tests the LinkIt parsing.
*/
......@@ -214,6 +235,27 @@ class EmbeddedContentTest extends EntityUsageJavascriptTestBase {
$this->assertEquals([], $usage);
}
/**
* Tests the LinkIt plugin parsing does not error with malformed HTML.
*/
public function testLinkItdWithMalformedHtml() {
$embedded_text = '<p>foo <a data-entity-substitution="canonical" data-entity-type="" data-entity-uuid="">linked text</a> bar</p>';
$node = Node::create([
'type' => 'eu_test_ct',
'title' => 'This is a node with malformed LinkIt HTML',
'field_eu_test_rich_text' => [
'value' => $embedded_text,
'format' => 'eu_test_text_format',
],
]);
$node->save();
$this->drupalGet('/node/' . $node->id());
$this->assertSession()->pageTextContains('This is a node with malformed LinkIt HTML');
}
/**
* Tests the HtmlLink parsing.
*/
......@@ -505,4 +547,25 @@ class EmbeddedContentTest extends EntityUsageJavascriptTestBase {
$this->assertEquals($expected, $usage);
}
/**
* Tests the MediaEmbed plugin parsing does not error with malformed HTML.
*/
public function testMediaEmbeddWithMalformedHtml() {
$embedded_text = '<drupal-media data-entity-type="media" data-entity-uuid=""></drupal-media>';
$node = Node::create([
'type' => 'eu_test_ct',
'title' => 'This is a node with malformed MediaEmbed HTML',
'field_eu_test_rich_text' => [
'value' => $embedded_text,
'format' => 'eu_test_text_format',
],
]);
$node->save();
$this->drupalGet('/node/' . $node->id());
$this->assertSession()->pageTextContains('This is a node with malformed MediaEmbed HTML');
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment