protected function MenuItemParser::firstChildUrl in Menu Firstchild 8
Same name and namespace in other branches
- 2.x src/MenuItemParser.php \Drupal\menu_firstchild\MenuItemParser::firstChildUrl()
 
Returns the URL of the first child of given menu item.
This does take into account menu_firstchild.
Parameters
array $item: Menu item array.
string $menu_name: Menu machine name.
Return value
\Drupal\Core\Url URL to use in the link.
File
- src/
MenuItemParser.php, line 78  
Class
- MenuItemParser
 - Class MenuItemParser.
 
Namespace
Drupal\menu_firstchildCode
protected function firstChildUrl(array $item, $menu_name) {
  // Get tree.
  $tree = $this
    ->childTree($item, $menu_name);
  // Children found, get url of first one.
  if (count($tree)) {
    $first_child = reset($tree);
    $url = $first_child->link
      ->getUrlObject();
  }
  else {
    $url = Url::fromRoute('<none>');
  }
  return $url;
}