You are here

function entity_embed_replace_dom_node_content in Entity Embed 7.3

Same name and namespace in other branches
  1. 7 includes/entity_embed.html.inc \entity_embed_replace_dom_node_content()
  2. 7.2 includes/entity_embed.html.inc \entity_embed_replace_dom_node_content()

Replace the contents of a DOMNode.

Parameters

\DOMElement $node: A DOMElement object.

string $content: The text or HTML that will replace the contents of $node.

1 call to entity_embed_replace_dom_node_content()
_entity_embed_render_placeholders in ./entity_embed.module
Implements callback_filter_process().

File

includes/entity_embed.html.inc, line 177
DOM processing functions.

Code

function entity_embed_replace_dom_node_content(\DOMElement $node, $content) {
  if (strlen($content)) {

    // Load the contents into a new DOMDocument and retrieve the element.
    $replacement_nodes = entity_embed_dom_load_html($content)
      ->getElementsByTagName('body')
      ->item(0)->childNodes;
  }
  else {
    $replacement_nodes = array(
      $node->ownerDocument
        ->createTextNode(''),
    );
  }
  foreach ($replacement_nodes as $replacement_node) {

    // Import the replacement node from the new DOMDocument into the original
    // one, importing also the child nodes of the replacement node.
    $replacement_node = $node->ownerDocument
      ->importNode($replacement_node, TRUE);
    $node->parentNode
      ->insertBefore($replacement_node, $node);
  }
  $node->parentNode
    ->removeChild($node);
}