setStringTranslation($translation); } /** * Adds an "overview" child link to second level menu links with children. * * In the navigation menu, a second-level menu item is a link if it does not * have children, but if it does, it instead becomes a button that opens * its child menu. To provide a way to access the page a second-level menu * item links to, add an "overview" link that links to the page as a child * (third-level) menu item. * * @param \Drupal\Core\Menu\MenuLinkTreeElement[] $tree * The menu link tree to manipulate. * * @return \Drupal\Core\Menu\MenuLinkTreeElement[] * The manipulated menu link tree. */ public function addSecondLevelOverviewLinks(array $tree): array { if (!$tree) { return []; } foreach ($tree as $item) { if (!$this->isEnabledAndAccessible($item)) { continue; } foreach ($item->subtree as $sub_item) { if ($this->shouldAddOverviewLink($sub_item)) { $this->addOverviewLink($sub_item); } } } return $tree; } /** * Whether a menu tree element should have an overview link added to it. * * @param \Drupal\Core\Menu\MenuLinkTreeElement $element * The menu link tree element to check. * * @return bool * TRUE if menu tree element should have a child overview link added. */ protected function shouldAddOverviewLink(MenuLinkTreeElement $element): bool { if (empty($element->subtree) || !$this->isEnabledAndAccessible($element)) { return FALSE; } $route_name = $element->link->getRouteName(); if (in_array($route_name, ['', '