You are here

protected static function InsertView::replaceNodeContent in Advanced Insert View 2.0.x

Replaces the contents of a DOMNode.

Parameters

\DOMNode $node: A DOMNode object.

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

1 call to InsertView::replaceNodeContent()
InsertView::processText in src/Plugin/Filter/InsertView.php
Process text to find <drupal-view> tags and replace with placeholders.

File

src/Plugin/Filter/InsertView.php, line 162

Class

InsertView
Provides a filter for insert view.

Namespace

Drupal\insert_view_adv\Plugin\Filter

Code

protected static function replaceNodeContent(\DOMNode &$node, $content) {
  if (strlen($content)) {

    // Load the content into a new DOMDocument and retrieve the DOM nodes.
    $replacement_nodes = Html::load($content)
      ->getElementsByTagName('body')
      ->item(0)->childNodes;
  }
  else {
    $replacement_nodes = [
      $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);
}