public function MenuLinksActiveTrail::resolve in Thunder 6.2.x
Resolver.
Parameters
\Drupal\system\MenuInterface $menu: The menu interface.
\Drupal\Core\Entity\ContentEntityInterface $entity: The content entity interface.
Return value
array The menu links.
Throws
\Drupal\Core\Entity\EntityMalformedException
File
- modules/
thunder_gqls/ src/ Plugin/ GraphQL/ DataProducer/ MenuLinksActiveTrail.php, line 105
Class
- MenuLinksActiveTrail
- Return the menu links of a menu with active trail.
Namespace
Drupal\thunder_gqls\Plugin\GraphQL\DataProducerCode
public function resolve(MenuInterface $menu, ContentEntityInterface $entity) {
$parameters = new MenuTreeParameters();
$links = $this->menuLinkManager
->loadLinksByRoute($entity
->toUrl()
->getRouteName(), $entity
->toUrl()
->getRouteParameters(), $menu
->id());
$activeLink = reset($links);
if ($activeLink) {
$activeTrail = [
'' => '',
];
if ($parents = $this->menuLinkManager
->getParentIds($activeLink
->getPluginId())) {
$activeTrail = $parents + $activeTrail;
}
$parameters
->setActiveTrail($activeTrail);
}
$tree = $this->menuLinkTree
->load($menu
->id(), $parameters);
$manipulators = [
[
'callable' => 'menu.default_tree_manipulators:checkAccess',
],
[
'callable' => 'menu.default_tree_manipulators:generateIndexAndSort',
],
];
return array_filter($this->menuLinkTree
->transform($tree, $manipulators), function (MenuLinkTreeElement $item) {
return $item->link instanceof MenuLinkInterface && $item->link
->isEnabled();
});
}