You are here

protected function AccessCheckBase::userIsAllowedToTranslateLanguage in Allowed Languages 8

Checks if the user is allowed to translate the specified language.

Parameters

\Drupal\user\UserInterface $user: The user to check.

\Drupal\Core\Language\LanguageInterface $language: The language to check for.

Return value

bool If the user is allowed to or not.

2 calls to AccessCheckBase::userIsAllowedToTranslateLanguage()
ContentTranslationAccessCheck::access in src/Access/ContentTranslationAccessCheck.php
Check language access when managing content translations.
EntityAccessCheck::access in src/Access/EntityAccessCheck.php
Allowed languages entity access check.

File

src/Access/AccessCheckBase.php, line 44

Class

AccessCheckBase
Allowed languages access check base class.

Namespace

Drupal\allowed_languages\Access

Code

protected function userIsAllowedToTranslateLanguage(UserInterface $user, LanguageInterface $language) {

  // Bypass the access check if the user has permission to translate all languages.
  if ($user
    ->hasPermission('translate all languages')) {
    return TRUE;
  }
  $allowed_languages = $this
    ->getUsersAllowedLanguages($user);
  return in_array($language
    ->getId(), $allowed_languages);
}