Skip to content

Commit

Permalink
Created module and base implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
Philippe von Bergen committed Aug 29, 2017
1 parent 0ac4a44 commit 68da6ae
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
6 changes: 6 additions & 0 deletions iq_lang_switcher.info.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
name: iQual Language Switcher Improvements
description: Disables inactive languages in front end.
package: Custom

type: module
core: 8.x
22 changes: 22 additions & 0 deletions iq_lang_switcher.module
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php
function iq_lang_switcher_language_switch_links_alter(array &$links, $type, $path)
{
if (\Drupal::currentUser()->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]);
}
}
}
}
}

0 comments on commit 68da6ae

Please sign in to comment.