You are here

public function ContextGroupsManager::getAllParentsForGroup in Context groups 8

Same name and namespace in other branches
  1. 8.2 src/ContextGroupsManager.php \Drupal\context_groups\ContextGroupsManager::getAllParentsForGroup()

Get all parents of an element.

Parameters

array $groups: Array of all groups.

string $group: Machine name of the group.

array $parents: Parents of group.

Return value

array Return all parents for group in hierarchic order.

File

src/ContextGroupsManager.php, line 121

Class

ContextGroupsManager
Class ContextGroupsManager.

Namespace

Drupal\context_groups

Code

public function getAllParentsForGroup(array $groups, $group, array $parents = []) {
  if (empty($group)) {
    return array_reverse($parents);
  }
  else {
    $parents[] = $group;
    return $this
      ->getAllParentsForGroup($groups, $groups[$group]['parent'], $parents);
  }
}