diff --git a/lib/Drupal/entity_embed/Plugin/Filter/EntityEmbedFilter.php b/lib/Drupal/entity_embed/Plugin/Filter/EntityEmbedFilter.php index 7a35e28f..0fdecaf8 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'); @@ -82,6 +89,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()) { + $node->removeChild($node->firstChild); + } // Finally, append the entity to the DOM node. $node->appendChild($updated_node);