Move getElementInnerHTML from button to DomDocumentHelper

[MAILPOET-5741]
This commit is contained in:
Rostislav Wolny
2024-02-22 12:35:57 +01:00
committed by Rostislav Wolný
parent febc070c0f
commit aa658782fb
2 changed files with 12 additions and 16 deletions

View File

@@ -27,7 +27,8 @@ class Button implements BlockRenderer {
$markup = str_replace('{classes}', $buttonClasses, $markup); $markup = str_replace('{classes}', $buttonClasses, $markup);
// Add Link Text // 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); $markup = str_replace('{linkUrl}', $buttonLink->getAttribute('href') ?: '#', $markup);
// Width // Width
@@ -115,19 +116,4 @@ class Button implements BlockRenderer {
</tr> </tr>
</table>'; </table>';
} }
/**
* 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;
}
} }

View File

@@ -47,4 +47,14 @@ class DomDocumentHelper {
public function getOuterHtml(\DOMElement $element): string { public function getOuterHtml(\DOMElement $element): string {
return (string)$this->dom->saveHTML($element); 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;
}
} }