From aa658782fbf9286a1e6cd62c56e64669aa04bee9 Mon Sep 17 00:00:00 2001 From: Rostislav Wolny Date: Thu, 22 Feb 2024 12:35:57 +0100 Subject: [PATCH] Move getElementInnerHTML from button to DomDocumentHelper [MAILPOET-5741] --- .../Core/Renderer/Blocks/Button.php | 18 ++---------------- .../Integrations/Utils/DomDocumentHelper.php | 10 ++++++++++ 2 files changed, 12 insertions(+), 16 deletions(-) diff --git a/mailpoet/lib/EmailEditor/Integrations/Core/Renderer/Blocks/Button.php b/mailpoet/lib/EmailEditor/Integrations/Core/Renderer/Blocks/Button.php index 5b3b4118ac..830b8fdeaf 100644 --- a/mailpoet/lib/EmailEditor/Integrations/Core/Renderer/Blocks/Button.php +++ b/mailpoet/lib/EmailEditor/Integrations/Core/Renderer/Blocks/Button.php @@ -27,7 +27,8 @@ class Button implements BlockRenderer { $markup = str_replace('{classes}', $buttonClasses, $markup); // Add Link Text - $markup = str_replace('{linkText}', $this->getElementInnerHTML($buttonLink) ?: '', $markup); + // Because the button text can contain highlighted text, we need to get the inner HTML of the button + $markup = str_replace('{linkText}', $domHelper->getElementInnerHTML($buttonLink) ?: '', $markup); $markup = str_replace('{linkUrl}', $buttonLink->getAttribute('href') ?: '#', $markup); // Width @@ -115,19 +116,4 @@ class Button implements BlockRenderer { '; } - - /** - * Because the button text can contain highlighted text, we need to get the inner HTML of the button - */ - private function getElementInnerHTML(\DOMElement $element): string { - $innerHTML = ''; - $children = $element->childNodes; - foreach ($children as $child) { - if (!$child instanceof \DOMNode) continue; - $ownerDocument = $child->ownerDocument; - if (!$ownerDocument instanceof \DOMDocument) continue; - $innerHTML .= $ownerDocument->saveXML($child); - } - return $innerHTML; - } } diff --git a/mailpoet/lib/EmailEditor/Integrations/Utils/DomDocumentHelper.php b/mailpoet/lib/EmailEditor/Integrations/Utils/DomDocumentHelper.php index b99b47fc1d..afcaf35882 100644 --- a/mailpoet/lib/EmailEditor/Integrations/Utils/DomDocumentHelper.php +++ b/mailpoet/lib/EmailEditor/Integrations/Utils/DomDocumentHelper.php @@ -47,4 +47,14 @@ class DomDocumentHelper { public function getOuterHtml(\DOMElement $element): string { return (string)$this->dom->saveHTML($element); } + + public function getElementInnerHTML(\DOMElement $element): string { + $innerHTML = ''; + $children = $element->childNodes; + foreach ($children as $child) { + if (!$child instanceof \DOMNode) continue; + $innerHTML .= $this->dom->saveHTML($child); + } + return $innerHTML; + } }