/**
  * {@inheritdoc}
  */
 public function access(Route $route, Request $request, AccountInterface $account)
 {
     // For the translation forms we have a target language, so we need some
     // checks in addition to the checks performed for the translation overview.
     $base_access = parent::access($route, $request, $account);
     if ($base_access === static::ALLOW) {
         $target_language = language_load($request->attributes->get('langcode'));
         // Make sure that the target language is not locked, and that the target
         // language is not the original submission language. Although technically
         // configuration can be overlaid with translations in the same language,
         // that is logically not a good idea.
         $access = !empty($target_language) && !$target_language->locked && $target_language->id != $this->sourceLanguage->id;
         return $access ? static::ALLOW : static::DENY;
     }
     return static::DENY;
 }
Пример #2
0
 /**
  * {@inheritdoc}
  */
 public function access(RouteMatchInterface $route_match, AccountInterface $account, $langcode = NULL)
 {
     // For the translation forms we have a target language, so we need some
     // checks in addition to the checks performed for the translation overview.
     $base_access = parent::access($route_match, $account);
     if ($base_access->isAllowed()) {
         $target_language = $this->languageManager->getLanguage($langcode);
         // Make sure that the target language is not locked, and that the target
         // language is not the original submission language. Although technically
         // configuration can be overlaid with translations in the same language,
         // that is logically not a good idea.
         $access = !empty($target_language) && !$target_language->isLocked() && (empty($this->sourceLanguage) || $target_language->getId() != $this->sourceLanguage->getId());
         return $base_access->andIf(AccessResult::allowedIf($access));
     }
     return $base_access;
 }
 /**
  * Checks access given an account, configuration mapper, and source language.
  *
  * In addition 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.
  *
  * 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)
 {
     $base_access_result = parent::doCheckAccess($account, $mapper, $source_language);
     $access = $target_language && !$target_language->isLocked() && (!$source_language || $target_language->getId() !== $source_language->getId());
     return $base_access_result->andIf(AccessResult::allowedIf($access));
 }