function MediaEmbed::replaceNodeContent
Same name in other branches
- 9 core/modules/media/src/Plugin/Filter/MediaEmbed.php \Drupal\media\Plugin\Filter\MediaEmbed::replaceNodeContent()
- 10 core/modules/media/src/Plugin/Filter/MediaEmbed.php \Drupal\media\Plugin\Filter\MediaEmbed::replaceNodeContent()
- 11.x core/modules/media/src/Plugin/Filter/MediaEmbed.php \Drupal\media\Plugin\Filter\MediaEmbed::replaceNodeContent()
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 MediaEmbed::replaceNodeContent()
- MediaEmbed::renderIntoDomNode in core/
modules/ media/ src/ Plugin/ Filter/ MediaEmbed.php - Renders the given render array into the given DOM node.
File
-
core/
modules/ media/ src/ Plugin/ Filter/ MediaEmbed.php, line 403
Class
- MediaEmbed
- Provides a filter to embed media items using a custom tag.
Namespace
Drupal\media\Plugin\FilterCode
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);
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.