protected function SpamspanDomTrait::replaceDomNode in SpamSpan filter 8.2
Same name and namespace in other branches
- 8 src/SpamspanDomTrait.php \Drupal\spamspan\SpamspanDomTrait::replaceDomNode()
Replace DOM node with another one created from text.
Parameters
\DOMNode $old_node: Node to be replaced.
string $new_text: Html for new node.
1 call to SpamspanDomTrait::replaceDomNode()
- SpamspanDomTrait::processAsDom in src/
SpamspanDomTrait.php - Replaces email addresses using DOM and regex.
File
- src/
SpamspanDomTrait.php, line 73
Class
- SpamspanDomTrait
- Trait SpamspanDomTrait.
Namespace
Drupal\spamspanCode
protected function replaceDomNode(\DOMNode $old_node, $new_text) {
$fragment = $this
->loadHtmlDocument($new_text);
$div = $fragment
->getElementsByTagName('div')
->item(0);
foreach ($div->childNodes as $child) {
$new_node = $old_node->ownerDocument
->importNode($child, TRUE);
$old_node->parentNode
->insertBefore($new_node, $old_node);
}
$old_node->parentNode
->removeChild($old_node);
}