function MenuLinkBase::getUrlObject

Same name and namespace in other branches
  1. 9 core/lib/Drupal/Core/Menu/MenuLinkBase.php \Drupal\Core\Menu\MenuLinkBase::getUrlObject()
  2. 8.9.x core/lib/Drupal/Core/Menu/MenuLinkBase.php \Drupal\Core\Menu\MenuLinkBase::getUrlObject()
  3. 11.x core/lib/Drupal/Core/Menu/MenuLinkBase.php \Drupal\Core\Menu\MenuLinkBase::getUrlObject()

Returns a URL object containing either the external path or route.

Parameters

bool $title_attribute: (optional) If TRUE, add the link description as the title attribute if the description is not empty.

Return value

\Drupal\Core\Url A URL object containing either the external path or route.

Overrides MenuLinkInterface::getUrlObject

File

core/lib/Drupal/Core/Menu/MenuLinkBase.php, line 122

Class

MenuLinkBase
Defines a base menu link class.

Namespace

Drupal\Core\Menu

Code

public function getUrlObject($title_attribute = TRUE) {
  $options = $this->getOptions();
  if ($title_attribute && ($description = $this->getDescription())) {
    $options['attributes']['title'] = $description;
  }
  if (empty($this->pluginDefinition['url'])) {
    return new Url($this->getRouteName(), $this->getRouteParameters(), $options);
  }
  else {
    return Url::fromUri($this->pluginDefinition['url'], $options);
  }
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.