public function CollapseText::findLevels in Collapse Text 8
Same name and namespace in other branches
- 2.0.x src/Plugin/Filter/CollapseText.php \Drupal\collapse_text\Plugin\Filter\CollapseText::findLevels()
Helper function to determine what the nesting structure is.
1 call to CollapseText::findLevels()
- CollapseText::process in src/Plugin/ Filter/ CollapseText.php 
- Performs the filter processing.
File
- src/Plugin/ Filter/ CollapseText.php, line 435 
Class
- CollapseText
- Provides a filter to display Collapsible text blocks.
Namespace
Drupal\collapse_text\Plugin\FilterCode
public function findLevels($tags, $options) {
  $levels = [];
  $curr_level = 0;
  foreach ($tags as $item) {
    // Determine whether this is an open or close tag.
    $type = 'unknown';
    if (substr($item[0], 0, 9) == '[collapse') {
      $type = 'start';
    }
    elseif (substr($item[0], 0, 10) == '[/collapse') {
      $type = 'end';
    }
    // The level of an open tag is incremented before we save its
    // information, while the level of a close tag is decremented after.
    if ($type == 'start') {
      $curr_level++;
    }
    $levels[] = [
      'type' => $type,
      'tag' => $item[0],
      'start' => $item[1],
      'end' => $item[1] + strlen($item[0]),
      'level' => $curr_level,
    ];
    if ($type == 'end') {
      $curr_level--;
    }
  }
  return $levels;
}