public function ContentTranslationAccessCheck::access in Allowed Languages 2.x
Same name and namespace in other branches
- 8 src/Access/ContentTranslationAccessCheck.php \Drupal\allowed_languages\Access\ContentTranslationAccessCheck::access()
Check language access when managing content translations.
This access check is based on the access check provided by the content translation module and uses the same parameters in the access callback.
Parameters
\Symfony\Component\Routing\Route $route: The route to check against.
\Drupal\Core\Routing\RouteMatchInterface $route_match: The parametrized route.
\Drupal\Core\Session\AccountInterface $account: The currently logged in account.
string $source: (optional) For a create operation, the language code of the source.
string $target: (optional) For a create operation, the language code of the translation.
string $language: (optional) For an update or delete operation, the language code of the translation being updated or deleted.
string $entity_type_id: (optional) The entity type ID.
Return value
\Drupal\Core\Access\AccessResultInterface The access result.
File
- src/
Access/ ContentTranslationAccessCheck.php, line 67
Class
- ContentTranslationAccessCheck
- Allowed languages content translation access check.
Namespace
Drupal\allowed_languages\AccessCode
public function access(Route $route, RouteMatchInterface $route_match, AccountInterface $account, $source = NULL, $target = NULL, $language = NULL, $entity_type_id = NULL) {
/**
* @var \Drupal\Core\Entity\ContentEntityInterface $entity
*/
$entity = $route_match
->getParameter($entity_type_id);
// If the entity could not be found on the parameters let other modules
// take care of the access check.
if (!$entity) {
return AccessResult::neutral();
}
$language = $this
->getTargetLanguage($target);
$user = $this->allowedLanguagesManager
->accountFromProxy($account);
if ($this->allowedLanguagesManager
->hasPermissionForLanguage($language, $user)) {
return AccessResult::allowed()
->cachePerUser()
->addCacheableDependency($user);
}
return AccessResult::forbidden()
->cachePerUser()
->addCacheableDependency($user);
}