function LanguageNegotiationContentEntity::getLanguageSwitchLinks

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

Overrides LanguageSwitcherInterface::getLanguageSwitchLinks

File

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

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;
}

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