You are here

public function AllowedLanguagesManager::hasPermissionForLanguage in Allowed Languages 2.x

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

Parameters

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

\Drupal\Core\Session\AccountInterface $account: The user to check.

Return value

bool If the user is allowed to or not.

Overrides AllowedLanguagesManagerInterface::hasPermissionForLanguage

File

src/AllowedLanguagesManager.php, line 87

Class

AllowedLanguagesManager
The allowed language manager controls access to content by language.

Namespace

Drupal\allowed_languages

Code

public function hasPermissionForLanguage(LanguageInterface $language, AccountInterface $account = NULL) {
  $account = $this
    ->accountFromProxy($this->currentUser);

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