You are here

public function LanguageNegotiationContentEntity::getLanguageSwitchLinks in Drupal 10

Same name and namespace in other branches
  1. 8 core/modules/language/src/Plugin/LanguageNegotiation/LanguageNegotiationContentEntity.php \Drupal\language\Plugin\LanguageNegotiation\LanguageNegotiationContentEntity::getLanguageSwitchLinks()
  2. 9 core/modules/language/src/Plugin/LanguageNegotiation/LanguageNegotiationContentEntity.php \Drupal\language\Plugin\LanguageNegotiation\LanguageNegotiationContentEntity::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;
}