You are here

protected function OgMenuTrait::getOgMenuTree in Organic Groups Menu (OG Menu) 8

Returns the menu link tree for the given OG Menu instance.

Parameters

\Drupal\og_menu\OgMenuInstanceInterface $instance: The OG Menu instance for which to return the menu tree.

int $min_depth: Optional minimum depth for populating the tree. Defaults to 1.

int $max_depth: Optional maximum depth for populating the tree. If omitted, the full depth will be used.

Return value

\Drupal\Core\Menu\MenuLinkTreeElement[] A menu link tree.

1 call to OgMenuTrait::getOgMenuTree()
OgMenuSubContext::assertMenuItemCount in ./og_menu.behat.inc
Checks that the given OG Menu instance has the expected number of items.

File

src/Tests/Traits/OgMenuTrait.php, line 111

Class

OgMenuTrait
Helper methods to use in OG Menu tests.

Namespace

Drupal\og_menu\Tests\Traits

Code

protected function getOgMenuTree(OgMenuInstanceInterface $instance, $min_depth = 1, $max_depth = NULL) {

  /** @var \Drupal\Core\Cache\CacheBackendInterface $menu_cache_service */
  $menu_cache_service = \Drupal::service('cache.menu');

  /** @var \Drupal\Core\Menu\MenuLinkTreeInterface $link_tree_service */
  $link_tree_service = \Drupal::service('menu.link_tree');

  // Load the menu link tree.
  $menu_name = 'ogmenu-' . $instance
    ->id();
  $parameters = $link_tree_service
    ->getCurrentRouteMenuTreeParameters($menu_name);
  $parameters
    ->setMinDepth($min_depth);
  $parameters
    ->setMaxDepth($max_depth);
  $parameters->expandedParents = [];

  // Clear the cache before loading it so we do not get outdated results. Sort
  // the 'conditions' so that it exactly matches the original cid.
  asort($parameters->conditions);
  $tree_cid = "tree-data:{$menu_name}:" . serialize($parameters);
  $menu_cache_service
    ->delete($tree_cid);
  return $link_tree_service
    ->load($menu_name, $parameters);
}