public function LanguageNegotiationContentEntity::getLanguageSwitchLinks in Drupal 8
Same name and namespace in other branches
- 9 core/modules/language/src/Plugin/LanguageNegotiation/LanguageNegotiationContentEntity.php \Drupal\language\Plugin\LanguageNegotiation\LanguageNegotiationContentEntity::getLanguageSwitchLinks()
- 10 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 146
Class
- LanguageNegotiationContentEntity
- Class for identifying the content translation language.
Namespace
Drupal\language\Plugin\LanguageNegotiationCode
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;
}