You are here

function language_access_simple_sitemap_links_alter in Language access 8

Implements hook_simple_sitemap_links_alter().

File

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

Code

function language_access_simple_sitemap_links_alter(array &$links) {
  $languages = \Drupal::languageManager()
    ->getLanguages();
  $user = User::getAnonymousUser();
  foreach ($links as $key => $link) {
    if (isset($languages[$link['langcode']]) && !$user
      ->hasPermission('access language ' . $link['langcode'])) {
      unset($links[$key]);
    }
    if (isset($link['alternate_urls'])) {
      foreach ($link['alternate_urls'] as $langcode => $alternate_url) {
        if (isset($languages[$langcode]) && !$user
          ->hasPermission('access language ' . $langcode)) {
          unset($links[$key]['alternate_urls'][$langcode]);
        }
      }
    }
  }
}