You are here

class WebformTranslationFormAccess in Webform Translation Permissions 8

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

Hierarchy

Expanded class hierarchy of WebformTranslationFormAccess

1 string reference to 'WebformTranslationFormAccess'
webform_translation_permissions.services.yml in ./webform_translation_permissions.services.yml
webform_translation_permissions.services.yml
1 service uses WebformTranslationFormAccess
webform.translation_form_access in ./webform_translation_permissions.services.yml
Drupal\webform_translation_permissions\Access\WebformTranslationFormAccess

File

src/Access/WebformTranslationFormAccess.php, line 13

Namespace

Drupal\webform_translation_permissions\Access
View source
class WebformTranslationFormAccess extends ConfigTranslationFormAccess {

  /**
   * 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.
   *
   * @param \Drupal\Core\Session\AccountInterface $account
   *   The account to check access for.
   * @param \Drupal\config_translation\ConfigMapperInterface $mapper
   *   The configuration mapper to check access for.
   * @param \Drupal\Core\Language\LanguageInterface|null $source_language
   *   The source language to check for, if any.
   * @param \Drupal\Core\Language\LanguageInterface|null $target_language
   *   The target language to check for, if any.
   *
   * @return \Drupal\Core\Access\AccessResultInterface
   *   The result of the access check.
   *
   * @see \Drupal\config_translation\Access\ConfigTranslationOverviewAccess::doCheckAccess()
   */
  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();
  }

}

Members

Namesort descending Modifiers Type Description Overrides
ConfigTranslationFormAccess::access public function Checks access to the overview based on permissions and translatability. Overrides ConfigTranslationOverviewAccess::access
ConfigTranslationOverviewAccess::$configMapperManager protected property The mapper plugin discovery service.
ConfigTranslationOverviewAccess::$languageManager protected property The language manager.
ConfigTranslationOverviewAccess::getMapperFromRouteMatch protected function Gets a configuration mapper using a route match.
ConfigTranslationOverviewAccess::__construct public function Constructs a ConfigTranslationOverviewAccess object.
WebformTranslationFormAccess::doCheckAccess protected function Checks access given an account, configuration mapper, and source language. Overrides ConfigTranslationFormAccess::doCheckAccess