You are here

protected function MenuItemParser::firstChildUrl in Menu Firstchild 2.x

Same name and namespace in other branches
  1. 8 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 90

Class

MenuItemParser
Class MenuItemParser.

Namespace

Drupal\menu_firstchild

Code

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;
}