protected function LanguageSwitcherLinkProcessor::processUntranslatedLinks in Language Switcher Extended 8
Processes all untranslated language switcher items.
Parameters
array $links: Language switcher links to be processed.
1 call to LanguageSwitcherLinkProcessor::processUntranslatedLinks()
- LanguageSwitcherLinkProcessor::process in src/
LanguageSwitcherLinkProcessor.php - Processes the language switcher links.
File
- src/
LanguageSwitcherLinkProcessor.php, line 125
Class
- LanguageSwitcherLinkProcessor
- Processes the Language Switcher links.
Namespace
Drupal\language_switcher_extendedCode
protected function processUntranslatedLinks(array &$links) {
$config = $this->configFactory
->get('language_switcher_extended.settings');
if ($entity = $this
->getPageEntity()) {
$untranslatedHandler = $config
->get('untranslated_handler');
foreach ($links as $langcode => $link) {
if (!$entity
->hasTranslation($langcode) || !$entity
->getTranslation($langcode)
->access('view')) {
switch ($untranslatedHandler) {
case 'hide_link':
unset($links[$langcode]);
break;
case 'link_to_front':
$links[$langcode]['url'] = new Url('<front>');
break;
case 'no_link':
unset($links[$langcode]['url']);
$links[$langcode]['attributes']['class'][] = 'language-link--untranslated';
break;
}
}
}
// Hides the links, if we have only a single language switcher item left.
if ($config
->get('hide_single_link') && count($links) < 2) {
$links = $config
->get('hide_single_link_block') ? NULL : [];
}
}
}