You are here

public function TreeBuilder::flattenTree in Token 8

Flatten a token tree.

Parameters

array $tree: The tree array as returned by TreeBuilderInterface::buildTree().

Return value

array The flattened version of the tree.

Overrides TreeBuilderInterface::flattenTree

1 call to TreeBuilder::flattenTree()
TreeBuilder::buildTree in src/TreeBuilder.php
Build a tree array of tokens used for themeing or information.

File

src/TreeBuilder.php, line 187

Class

TreeBuilder

Namespace

Drupal\token

Code

public function flattenTree(array $tree) {
  $result = [];
  foreach ($tree as $token => $token_info) {
    $result[$token] = $token_info;
    if (isset($token_info['children']) && is_array($token_info['children'])) {
      $result += $this
        ->flattenTree($token_info['children']);
    }
  }
  return $result;
}