From 7a486f288411317f829857f0c7262de70b87d473 Mon Sep 17 00:00:00 2001 From: Chandan Singh Date: Sat, 17 May 2014 14:14:13 +0530 Subject: [PATCH 1/3] Remove all children of the node from the existing DOMDocument. --- lib/Drupal/entity_embed/Plugin/Filter/EntityEmbedFilter.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lib/Drupal/entity_embed/Plugin/Filter/EntityEmbedFilter.php b/lib/Drupal/entity_embed/Plugin/Filter/EntityEmbedFilter.php index 7a35e28f..ac2ad841 100644 --- a/lib/Drupal/entity_embed/Plugin/Filter/EntityEmbedFilter.php +++ b/lib/Drupal/entity_embed/Plugin/Filter/EntityEmbedFilter.php @@ -82,6 +82,10 @@ public function process($text, $langcode, $cache, $cache_id) { // one, importing also the child nodes of the updated node. $updated_node = $dom->importNode($updated_node, TRUE); + // Remove all children of the node from the existing DOMDocument. + while ($node->hasChildNodes() == TRUE) { + $node->removeChild($node->firstChild); + } // Finally, append the entity to the DOM node. $node->appendChild($updated_node); From 0120856fc4f83d7c75aac591d14eab388df7006d Mon Sep 17 00:00:00 2001 From: Chandan Singh Date: Sat, 17 May 2014 18:24:12 +0530 Subject: [PATCH 2/3] Continue only if specified entity type exists. --- .../entity_embed/Plugin/Filter/EntityEmbedFilter.php | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/lib/Drupal/entity_embed/Plugin/Filter/EntityEmbedFilter.php b/lib/Drupal/entity_embed/Plugin/Filter/EntityEmbedFilter.php index ac2ad841..9480de13 100644 --- a/lib/Drupal/entity_embed/Plugin/Filter/EntityEmbedFilter.php +++ b/lib/Drupal/entity_embed/Plugin/Filter/EntityEmbedFilter.php @@ -38,6 +38,13 @@ public function process($text, $langcode, $cache, $cache_id) { $entity = NULL; $view_mode = $node->getAttribute('data-view-mode'); + // Continue only if specified entity type exists. + $entity_info = \Drupal::entityManager()->getDefinition($entity_type); + if($entity_info == NULL) { + watchdog($entity_type, "Specified entity type '%entity_type' does not exists.", array('%entity_type' => $entity_type)); + return $text; + } + // Load the entity either by UUID (preferred) or ID. if ($node->hasAttribute('data-entity-uuid')) { $uuid = $node->getAttribute('data-entity-uuid'); From aafccf4f9dae84537605edafd3ebdbcc7c7145fb Mon Sep 17 00:00:00 2001 From: Chandan Singh Date: Tue, 20 May 2014 22:29:31 +0530 Subject: [PATCH 3/3] Unnecessary boolean comaprison skipped. --- lib/Drupal/entity_embed/Plugin/Filter/EntityEmbedFilter.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Drupal/entity_embed/Plugin/Filter/EntityEmbedFilter.php b/lib/Drupal/entity_embed/Plugin/Filter/EntityEmbedFilter.php index ac2ad841..9fce7ead 100644 --- a/lib/Drupal/entity_embed/Plugin/Filter/EntityEmbedFilter.php +++ b/lib/Drupal/entity_embed/Plugin/Filter/EntityEmbedFilter.php @@ -83,7 +83,7 @@ public function process($text, $langcode, $cache, $cache_id) { $updated_node = $dom->importNode($updated_node, TRUE); // Remove all children of the node from the existing DOMDocument. - while ($node->hasChildNodes() == TRUE) { + while ($node->hasChildNodes()) { $node->removeChild($node->firstChild); } // Finally, append the entity to the DOM node.