doCheckAccess example

try {
      $langcode = $mapper->getLangcode();
    }
    catch (ConfigMapperLanguageException $exception) {
      // ConfigTranslationController shows a helpful message if the language       // codes do not match, so do not let that prevent granting access.       $langcode = 'en';
    }
    $source_language = $this->languageManager->getLanguage($langcode);

    return $this->doCheckAccess($account$mapper$source_language);
  }

  /** * Gets a configuration mapper using a route match. * * @param \Drupal\Core\Routing\RouteMatchInterface $route_match * The route match to populate the mapper with. * * @return \Drupal\config_translation\ConfigMapperInterface * The configuration mapper. */
  

  public function access(RouteMatchInterface $route_match, AccountInterface $account$langcode = NULL) {
    $mapper = $this->getMapperFromRouteMatch($route_match);

    try {
      $source_langcode = $mapper->getLangcode();
      $source_language = $this->languageManager->getLanguage($source_langcode);

      $target_language = $this->languageManager->getLanguage($langcode);

      return $this->doCheckAccess($account$mapper$source_language$target_language);
    }
    catch (ConfigMapperLanguageException $exception) {
      return AccessResult::forbidden();
    }
  }

  /** * 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() */
Home | Imprint | This part of the site doesn't use cookies.