You are here

protected function WebformTranslationFormAccess::doCheckAccess in Webform Translation Permissions 8

Checks access given an account, configuration mapper, and source language.

Similar to the checks performed by ConfigTranslationOverviewAccess::doCheckAccess() this makes sure the target language is not locked and the target language is not the source language. Additionally, this checks the permissions for 'translate any' and 'translate own' webform.

Although technically configuration can be overlaid with translations in the same language, that is logically not a good idea.

Parameters

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

\Drupal\config_translation\ConfigMapperInterface $mapper: The configuration mapper to check access for.

\Drupal\Core\Language\LanguageInterface|null $source_language: The source language to check for, if any.

\Drupal\Core\Language\LanguageInterface|null $target_language: The target language to check for, if any.

Return value

\Drupal\Core\Access\AccessResultInterface The result of the access check.

Overrides ConfigTranslationFormAccess::doCheckAccess

See also

\Drupal\config_translation\Access\ConfigTranslationOverviewAccess::doCheckAccess()

File

src/Access/WebformTranslationFormAccess.php, line 43

Class

WebformTranslationFormAccess
Checks access for displaying the translation add, edit, and delete forms.

Namespace

Drupal\webform_translation_permissions\Access

Code

protected function doCheckAccess(AccountInterface $account, ConfigMapperInterface $mapper, $source_language = NULL, $target_language = NULL) {
  $entity = $mapper
    ->getEntity();
  $uid = $entity
    ->getOwnerId();
  $is_owner = $account
    ->isAuthenticated() && $account
    ->id() == $uid;
  $access = ($account
    ->hasPermission('translate configuration') || $account
    ->hasPermission('translate any webform') || $account
    ->hasPermission('translate own webform') && $is_owner) && $mapper
    ->hasSchema() && $mapper
    ->hasTranslatable() && (!$source_language || !$source_language
    ->isLocked());
  return AccessResult::allowedIf($access)
    ->cachePerPermissions();
}