Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. LanguageNegotiationUrl.php

function LanguageNegotiationUrl::getLanguageSwitchLinks

Overrides LanguageSwitcherInterface::getLanguageSwitchLinks

File

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

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 = [];
    parse_str($request->getQueryString() ?? '', $query);
    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;
}

API Navigation

  • Drupal Core 11.1.x
  • Topics
  • Classes
  • Functions
  • Constants
  • Globals
  • Files
  • Namespaces
  • Deprecated
  • Services
RSS feed
Powered by Drupal