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

Breadcrumb

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

function LanguageNegotiationContentEntity::getLanguageSwitchLinks

Overrides LanguageSwitcherInterface::getLanguageSwitchLinks

File

core/modules/language/src/Plugin/LanguageNegotiation/LanguageNegotiationContentEntity.php, line 145

Class

LanguageNegotiationContentEntity
Class for identifying the content translation language.

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) {
        $langcode = $language->getId();
        $query[static::QUERY_PARAMETER] = $langcode;
        $links[$langcode] = [
            'url' => $url,
            'title' => $language->getName(),
            '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