public function LanguageNegotiationSession::getLanguageSwitchLinks in Zircon Profile 8
Same name and namespace in other branches
- 8.0 core/modules/language/src/Plugin/LanguageNegotiation/LanguageNegotiationSession.php \Drupal\language\Plugin\LanguageNegotiation\LanguageNegotiationSession::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/ LanguageNegotiationSession.php, line 136 - Contains \Drupal\language\Plugin\LanguageNegotiation\LanguageNegotiationSession.
Class
- LanguageNegotiationSession
- Identify language from a request/session parameter.
Namespace
Drupal\language\Plugin\LanguageNegotiationCode
public function getLanguageSwitchLinks(Request $request, $type, Url $url) {
$links = array();
$config = $this->config
->get('language.negotiation')
->get('session');
$param = $config['parameter'];
$language_query = isset($_SESSION[$param]) ? $_SESSION[$param] : $this->languageManager
->getCurrentLanguage($type)
->getId();
$query = array();
parse_str($request
->getQueryString(), $query);
foreach ($this->languageManager
->getNativeLanguages() as $language) {
$langcode = $language
->getId();
$links[$langcode] = array(
// We need to clone the $url object to avoid using the same one for all
// links. When the links are rendered, options are set on the $url
// object, so if we use the same one, they would be set for all links.
'url' => clone $url,
'title' => $language
->getName(),
'attributes' => array(
'class' => array(
'language-link',
),
),
'query' => $query,
);
if ($language_query != $langcode) {
$links[$langcode]['query'][$param] = $langcode;
}
else {
$links[$langcode]['attributes']['class'][] = 'session-active';
}
}
return $links;
}