You are here

public function CollapseText::processRecurseTree in Collapse Text 2.0.x

Same name and namespace in other branches
  1. 8 src/Plugin/Filter/CollapseText.php \Drupal\collapse_text\Plugin\Filter\CollapseText::processRecurseTree()

Helper function to take a nested tree and turn it into a string.

This function is recursive.

2 calls to CollapseText::processRecurseTree()
CollapseText::process in src/Plugin/Filter/CollapseText.php
Performs the filter processing.
CollapseText::processChildItem in src/Plugin/Filter/CollapseText.php
Helper function to process a child item.

File

src/Plugin/Filter/CollapseText.php, line 195

Class

CollapseText
Provides a filter to display Collapsible text blocks.

Namespace

Drupal\collapse_text\Plugin\Filter

Code

public function processRecurseTree($tree, $options) {
  $parts = [];

  // We use $weight to make sure elements are displayed in the correct order.
  $weight = 0;
  foreach ($tree as $item) {

    // Iterate over the tree.
    $part = NULL;
    if ($item['type'] == 'text') {
      $part = $this
        ->processTextItem($item['value'], $options);
    }
    elseif ($item['type'] = 'child') {
      $part = $this
        ->processChildItem($item, $options);
    }
    if (isset($part)) {
      $part['#weight'] = $weight++;
      $parts[] = $part;
    }
  }
  return $parts;
}