You are here

protected function TreeHelper::getTreeFromGroups in Views tree 8.2

Get a tree from given groups.

Parameters

array $groups: The groups.

string $current_group: The current group.

Return value

\Drupal\views_tree\TreeItem The tree for the given groups.

1 call to TreeHelper::getTreeFromGroups()
TreeHelper::getTreeFromResult in src/TreeHelper.php
Builds a tree from a views result.

File

src/TreeHelper.php, line 82

Class

TreeHelper
The tree helper service.

Namespace

Drupal\views_tree

Code

protected function getTreeFromGroups(array $groups, $current_group = '0') {
  $return = new TreeItem(NULL);
  if (empty($groups[$current_group])) {
    return $return;
  }
  foreach ($groups[$current_group] as $item) {
    $tree_item = new TreeItem($item);
    $return
      ->addLeave($tree_item);
    $tree_item
      ->setLeaves($this
      ->getTreeFromGroups($groups, $item->views_tree_main)
      ->getLeaves());
  }
  return $return;
}