function LanguageNegotiationUrl::getLanguageSwitchLinks

Same name in other branches
  1. 9 core/modules/language/src/Plugin/LanguageNegotiation/LanguageNegotiationUrl.php \Drupal\language\Plugin\LanguageNegotiation\LanguageNegotiationUrl::getLanguageSwitchLinks()
  2. 10 core/modules/language/src/Plugin/LanguageNegotiation/LanguageNegotiationUrl.php \Drupal\language\Plugin\LanguageNegotiation\LanguageNegotiationUrl::getLanguageSwitchLinks()
  3. 11.x core/modules/language/src/Plugin/LanguageNegotiation/LanguageNegotiationUrl.php \Drupal\language\Plugin\LanguageNegotiation\LanguageNegotiationUrl::getLanguageSwitchLinks()

Overrides LanguageSwitcherInterface::getLanguageSwitchLinks

File

core/modules/language/src/Plugin/LanguageNegotiation/LanguageNegotiationUrl.php, line 196

Class

LanguageNegotiationUrl
Class for identifying language via URL prefix or domain.

Namespace

Drupal\language\Plugin\LanguageNegotiation

Code

public function getLanguageSwitchLinks(Request $request, $type, Url $url) {
    $links = [];
    $query = $request->query
        ->all();
    foreach ($this->languageManager
        ->getNativeLanguages() as $language) {
        $links[$language->getId()] = [
            // We need to clone the $url object to avoid using the same one for all
            // links. When the links are rendered, options are set on the $url
            // object, so if we use the same one, they would be set for all links.
'url' => clone $url,
            'title' => $language->getName(),
            'language' => $language,
            'attributes' => [
                'class' => [
                    'language-link',
                ],
            ],
            'query' => $query,
        ];
    }
    return $links;
}

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