public function EntityAccessCheck::access in Allowed Languages 8
Allowed languages entity access check.
Parameters
\Symfony\Component\Routing\Route $route: The current route.
\Drupal\Core\Routing\RouteMatchInterface $route_match: The current route match.
\Drupal\Core\Session\AccountInterface $account: The current user account.
Return value
\Drupal\Core\Access\AccessResultInterface Result from the access check.
File
- src/
Access/ EntityAccessCheck.php, line 63
Class
- EntityAccessCheck
- Allowed languages entity access check.
Namespace
Drupal\allowed_languages\AccessCode
public function access(Route $route, RouteMatchInterface $route_match, AccountInterface $account) {
// Split the entity type and the operation.
$requirement = $route
->getRequirement('_entity_access');
list($entity_type, $operation) = explode('.', $requirement);
// Only perform the access check when performing update/delete operations.
if (!in_array($operation, [
'update',
'delete',
])) {
return AccessResult::allowed();
}
$parameters = $route_match
->getParameters();
// If the entity type parameter is missing, let other modules
// take care of the access check then.
if (!$parameters
->has($entity_type)) {
return AccessResult::allowed();
}
$entity = $parameters
->get($entity_type);
// Only check the access for entities that are content entities since this
// module only support translatable content entities.
// Also exclude non-translatable content types from
// allowed languages' access control.
if (!$entity instanceof ContentEntityInterface || !$entity
->isTranslatable()) {
return AccessResult::allowed();
}
// @todo Remove usage of the url language service when a better solution
// is found.
$language = $this->urlLanguageService
->getUrlLanguage() ?: $entity
->language();
$user = $this
->loadUserEntityFromAccountProxy($account);
if ($this
->userIsAllowedToTranslateLanguage($user, $language)) {
return AccessResult::allowed();
}
// Access check failed so do not allow the user to translate the specified
// language.
return AccessResult::forbidden();
}