You are here

function language_access_language_switch_links_alter in Language access 8

Same name and namespace in other branches
  1. 7 language_access.module \language_access_language_switch_links_alter()

Implements hook_language_switch_links_alter().

File

./language_access.module, line 40
Provide access permissions by language.

Code

function language_access_language_switch_links_alter(array &$links, $type, Url $url) {
  $languages = \Drupal::languageManager()
    ->getLanguages();
  foreach ($languages as $language) {
    if (!\Drupal::currentUser()
      ->hasPermission('access language ' . $language
      ->getId())) {
      if (isset($links[$language
        ->getId()])) {
        unset($links[$language
          ->getId()]);
      }
    }
  }
}