From 722f9641bccaa011263383dbb94e779abcf9cc4c Mon Sep 17 00:00:00 2001 From: Alexander Ebert Date: Wed, 30 Jan 2019 13:51:24 +0100 Subject: [PATCH] Preserve element attributes on rename --- .../html/node/AbstractHtmlNodeProcessor.class.php | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/wcfsetup/install/files/lib/system/html/node/AbstractHtmlNodeProcessor.class.php b/wcfsetup/install/files/lib/system/html/node/AbstractHtmlNodeProcessor.class.php index 3947a06e1c..57fce6e751 100644 --- a/wcfsetup/install/files/lib/system/html/node/AbstractHtmlNodeProcessor.class.php +++ b/wcfsetup/install/files/lib/system/html/node/AbstractHtmlNodeProcessor.class.php @@ -163,10 +163,18 @@ abstract class AbstractHtmlNodeProcessor implements IHtmlNodeProcessor { * * @param \DOMElement $element old element * @param string $tagName tag name for the new element + * @param bool $preserveAttributes retain attributes for the new element * @return \DOMElement newly created element */ - public function renameTag(\DOMElement $element, $tagName) { + public function renameTag(\DOMElement $element, $tagName, $preserveAttributes = false) { $newElement = $this->document->createElement($tagName); + if ($preserveAttributes) { + /** @var \DOMNode $attribute */ + foreach ($element->attributes as $attribute) { + $newElement->setAttribute($attribute->nodeName, $attribute->nodeValue); + } + } + $element->parentNode->insertBefore($newElement, $element); while ($element->hasChildNodes()) { $newElement->appendChild($element->firstChild); @@ -223,7 +231,7 @@ abstract class AbstractHtmlNodeProcessor implements IHtmlNodeProcessor { $this->nodeData[] = [ 'data' => $data, 'identifier' => $nodeIdentifier, - 'object' => $htmlNode + 'object' => $htmlNode, ]; } -- 2.20.1