protected function TruncateHTML::insertEllipsis in Smart Trim 8
Inserts the Elipsis character to the node.
Parameters
\DOMNode $domnode: Node to be altered.
2 calls to TruncateHTML::insertEllipsis()
- TruncateHTML::domNodeTruncateChars in src/
Truncate/ TruncateHTML.php - Truncates a DOMNode by character count.
- TruncateHTML::domNodeTruncateWords in src/
Truncate/ TruncateHTML.php - Truncates a DOMNode by words.
File
- src/
Truncate/ TruncateHTML.php, line 288 - Contains trim functionality.
Class
- TruncateHTML
- Class TruncateHTML.
Namespace
Drupal\smart_trim\TruncateCode
protected function insertEllipsis(\DOMNode $domnode) {
// HTML tags to avoid appending the ellipsis to.
$avoid = [
'a',
'strong',
'em',
'h1',
'h2',
'h3',
'h4',
'h5',
];
if (in_array($domnode->parentNode->nodeName, $avoid) && ($domnode->parentNode->parentNode !== NULL || $domnode->parentNode->parentNode !== $this->startNode)) {
// Append as text node to parent instead.
$textnode = new \DOMText($this->ellipsis);
if ($domnode->parentNode->parentNode->nextSibling) {
$domnode->parentNode->parentNode
->insertBefore($textnode, $domnode->parentNode->parentNode->nextSibling);
}
else {
$domnode->parentNode->parentNode
->appendChild($textnode);
}
}
else {
// Append to current node.
$domnode->nodeValue = rtrim($domnode->nodeValue) . $this->ellipsis;
}
}