Add getAttributeValueByTagName to dom helper
I'm adding this method to cover use-cases where we need to extract classes from a block's HTML. [MAILPOET-5741]
This commit is contained in:
committed by
Rostislav Wolný
parent
875fde56e9
commit
d35e498f36
@@ -33,6 +33,17 @@ class DomDocumentHelper {
|
||||
return $element->hasAttribute($attribute) ? $element->getAttribute($attribute) : '';
|
||||
}
|
||||
|
||||
/**
|
||||
* Searches for the first appearance of the given tag name and returns the value of specified attribute.
|
||||
*/
|
||||
public function getAttributeValueByTagName(string $tagName, string $attribute): ?string {
|
||||
$element = $this->findElement($tagName);
|
||||
if (!$element) {
|
||||
return null;
|
||||
}
|
||||
return $this->getAttributeValue($element, $attribute);
|
||||
}
|
||||
|
||||
public function getOuterHtml(\DOMElement $element): string {
|
||||
return (string)$this->dom->saveHTML($element);
|
||||
}
|
||||
|
Reference in New Issue
Block a user