function entity_embed_change_dom_node_name in Entity Embed 7.2
Same name and namespace in other branches
- 7.3 includes/entity_embed.html.inc \entity_embed_change_dom_node_name()
- 7 includes/entity_embed.html.inc \entity_embed_change_dom_node_name()
Rename a DOMNode tag.
Parameters
\DOMNode $node: A DOMElement object.
string $name: The new tag name.
File
- includes/
entity_embed.html.inc, line 118 - DOM processing functions.
Code
function entity_embed_change_dom_node_name(\DOMNode &$node, $name = 'div') {
if ($node->nodeName != $name) {
/** @var \DOMElement $replacement_node */
$replacement_node = $node->ownerDocument
->createElement($name);
// Copy all children of the original node to the new node.
if ($node->childNodes->length) {
foreach ($node->childNodes as $child) {
$child = $replacement_node->ownerDocument
->importNode($child, TRUE);
$replacement_node
->appendChild($child);
}
}
// Copy all attributes of the original node to the new node.
if ($node->attributes->length) {
foreach ($node->attributes as $attribute) {
$replacement_node
->setAttribute($attribute->nodeName, $attribute->nodeValue);
}
}
$node->parentNode
->replaceChild($replacement_node, $node);
$node = $replacement_node;
}
}