Chris@0: configMapperManager = $config_mapper_manager; Chris@0: $this->languageManager = $language_manager; Chris@0: } Chris@0: Chris@0: /** Chris@0: * Checks access to the overview based on permissions and translatability. Chris@0: * Chris@0: * @param \Drupal\Core\Routing\RouteMatchInterface $route_match Chris@0: * The route_match to check against. Chris@0: * @param \Drupal\Core\Session\AccountInterface $account Chris@0: * The account to check access for. Chris@0: * Chris@0: * @return \Drupal\Core\Access\AccessResultInterface Chris@0: * The access result. Chris@0: */ Chris@0: public function access(RouteMatchInterface $route_match, AccountInterface $account) { Chris@0: $mapper = $this->getMapperFromRouteMatch($route_match); Chris@0: Chris@0: try { Chris@0: $langcode = $mapper->getLangcode(); Chris@0: } Chris@0: catch (ConfigMapperLanguageException $exception) { Chris@0: // ConfigTranslationController shows a helpful message if the language Chris@0: // codes do not match, so do not let that prevent granting access. Chris@0: $langcode = 'en'; Chris@0: } Chris@0: $source_language = $this->languageManager->getLanguage($langcode); Chris@0: Chris@0: return $this->doCheckAccess($account, $mapper, $source_language); Chris@0: } Chris@0: Chris@0: /** Chris@0: * Gets a configuration mapper using a route match. Chris@0: * Chris@0: * @param \Drupal\Core\Routing\RouteMatchInterface $route_match Chris@0: * The route match to populate the mapper with. Chris@0: * Chris@0: * @return \Drupal\config_translation\ConfigMapperInterface Chris@0: * The configuration mapper. Chris@0: */ Chris@0: protected function getMapperFromRouteMatch(RouteMatchInterface $route_match) { Chris@0: $mapper = $this->configMapperManager->createInstance($route_match->getRouteObject() Chris@0: ->getDefault('plugin_id')); Chris@0: $mapper->populateFromRouteMatch($route_match); Chris@0: return $mapper; Chris@0: } Chris@0: Chris@0: /** Chris@0: * Checks access given an account, configuration mapper, and source language. Chris@0: * Chris@0: * Grants access if the proper permission is granted to the account, the Chris@0: * configuration has translatable pieces, and the source language is not Chris@0: * locked given it is present. Chris@0: * Chris@0: * @param \Drupal\Core\Session\AccountInterface $account Chris@0: * The account to check access for. Chris@0: * @param \Drupal\config_translation\ConfigMapperInterface $mapper Chris@0: * The configuration mapper to check access for. Chris@0: * @param \Drupal\Core\Language\LanguageInterface|null $source_language Chris@0: * The source language to check for, if any. Chris@0: * Chris@0: * @return \Drupal\Core\Access\AccessResultInterface Chris@0: * The result of the access check. Chris@0: */ Chris@0: protected function doCheckAccess(AccountInterface $account, ConfigMapperInterface $mapper, $source_language = NULL) { Chris@0: $access = Chris@0: $account->hasPermission('translate configuration') && Chris@0: $mapper->hasSchema() && Chris@0: $mapper->hasTranslatable() && Chris@0: (!$source_language || !$source_language->isLocked()); Chris@0: Chris@0: return AccessResult::allowedIf($access)->cachePerPermissions(); Chris@0: } Chris@0: Chris@0: }