diff --git a/iq_lang_switcher.info.yml b/iq_lang_switcher.info.yml new file mode 100644 index 0000000..5633298 --- /dev/null +++ b/iq_lang_switcher.info.yml @@ -0,0 +1,6 @@ +name: iQual Language Switcher Improvements +description: Disables inactive languages in front end. +package: Custom + +type: module +core: 8.x \ No newline at end of file diff --git a/iq_lang_switcher.module b/iq_lang_switcher.module new file mode 100644 index 0000000..7ced88a --- /dev/null +++ b/iq_lang_switcher.module @@ -0,0 +1,22 @@ +hasPermission('bypass node access')) { + return; + } + if ($node = \Drupal::routeMatch()->getParameter('node')) { + $translations = $node->getTranslationLanguages(true); + foreach ($links as $langcode => $link) { + if ($node) { + if (array_key_exists($langcode, $translations)) { + $translation = $node->getTranslation($langcode); + if (!$translation->isPublished()) { + unset($links[$langcode]); + } + } else { + unset($links[$langcode]); + } + } + } + } +}