You are here

public function LanguageSwitchMenuLink::getUrlObject in Cheeseburger Menu 5.0.x

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 MenuLinkBase::getUrlObject

File

src/Plugin/Menu/LanguageSwitchMenuLink.php, line 99

Class

LanguageSwitchMenuLink
Language swithcher link - dynamically changes based on langcode.

Namespace

Drupal\cheeseburger_menu\Plugin\Menu

Code

public function getUrlObject($title_attribute = TRUE) {
  if ($this->pathMatcher
    ->isFrontPage()) {
    $url = Url::fromRoute('<front>');
  }
  else {
    $current_route = $this->routeMatch
      ->getRouteObject();
    $options = $current_route
      ->getOptions();
    $url = Url::fromRoute($this->routeMatch
      ->getRouteName(), $this->routeMatch
      ->getRawParameters()
      ->all(), $options);
  }
  $language = $this->languageManager
    ->getLanguage($this
    ->getPluginDefinition()['options']['langcode']);
  return $url
    ->setOption('language', $language);
}