You are here

protected function TruncateHTML::removeProceedingNodes in Smart Trim 8

Removes preceding sibling node.

Parameters

\DOMNode $domnode: Node to be altered.

2 calls to TruncateHTML::removeProceedingNodes()
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 260
Contains trim functionality.

Class

TruncateHTML
Class TruncateHTML.

Namespace

Drupal\smart_trim\Truncate

Code

protected function removeProceedingNodes(\DOMNode $domnode) {
  $nextnode = $domnode->nextSibling;
  if ($nextnode !== NULL) {
    $this
      ->removeProceedingNodes($nextnode);
    $domnode->parentNode
      ->removeChild($nextnode);
  }
  else {

    // Scan upwards till we find a sibling.
    $curnode = $domnode->parentNode;
    while ($curnode !== $this->startNode) {
      if ($curnode->nextSibling !== NULL) {
        $curnode = $curnode->nextSibling;
        $this
          ->removeProceedingNodes($curnode);
        $curnode->parentNode
          ->removeChild($curnode);
        break;
      }
      $curnode = $curnode->parentNode;
    }
  }
}