Browse Source

Fixed ownerDocument issue with TemplateElement

ns
Dustin Wilson 3 years ago
parent
commit
4f2ded817c
  1. 18
      lib/DOM/Document.php

18
lib/DOM/Document.php

@ -67,6 +67,15 @@ class Document extends \DOMDocument {
$e = parent::createElement($name, $value);
} else {
$e = new TemplateElement($name, $value);
// Elements that are created by their constructor in PHP aren't owned by any
// document and are readonly until owned by one. Temporarily append to a
// document fragment so the element will be owned by the document.
$frag = $this->createDocumentFragment();
$frag->appendChild($e);
$frag->removeChild($e);
unset($frag);
$this->templateElements[] = $e;
$e->content = $this->createDocumentFragment();
}
@ -88,6 +97,15 @@ class Document extends \DOMDocument {
$e = parent::createElementNS($namespaceURI, $qualifiedName, $value);
} else {
$e = new TemplateElement($qualifiedName, $value);
// Elements that are created by their constructor in PHP aren't owned by any
// document and are readonly until owned by one. Temporarily append to a
// document fragment so the element will be owned by the document.
$frag = $this->createDocumentFragment();
$frag->appendChild($e);
$frag->removeChild($e);
unset($frag);
$this->templateElements[] = $e;
$e->content = $this->createDocumentFragment();
}

Loading…
Cancel
Save