You are here

public function LanguageNegotiationContentEntity::getLanguageSwitchLinks in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/modules/language/src/Plugin/LanguageNegotiation/LanguageNegotiationContentEntity.php \Drupal\language\Plugin\LanguageNegotiation\LanguageNegotiationContentEntity::getLanguageSwitchLinks()

Returns language switch links.

Parameters

\Symfony\Component\HttpFoundation\Request $request: The current request.

string $type: The language type.

\Drupal\Core\Url $url: The URL the switch links will be relative to.

Return value

array An array of link arrays keyed by language code.

Overrides LanguageSwitcherInterface::getLanguageSwitchLinks

File

core/modules/language/src/Plugin/LanguageNegotiation/LanguageNegotiationContentEntity.php, line 157
Contains \Drupal\language\Plugin\LanguageNegotiation\LanguageNegotiationContentEntity.

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