class EntityAccessCheck in Zircon Profile 8
Same name and namespace in other branches
- 8.0 core/lib/Drupal/Core/Entity/EntityAccessCheck.php \Drupal\Core\Entity\EntityAccessCheck
Provides a generic access checker for entities.
Hierarchy
- class \Drupal\Core\Entity\EntityAccessCheck implements AccessInterface
Expanded class hierarchy of EntityAccessCheck
1 file declares its use of EntityAccessCheck
- EntityAccessCheckTest.php in core/
tests/ Drupal/ Tests/ Core/ Entity/ EntityAccessCheckTest.php - Contains \Drupal\Tests\Core\Entity\EntityAccessCheckTest.
1 string reference to 'EntityAccessCheck'
- core.services.yml in core/
core.services.yml - core/core.services.yml
1 service uses EntityAccessCheck
File
- core/
lib/ Drupal/ Core/ Entity/ EntityAccessCheck.php, line 19 - Contains \Drupal\Core\Entity\EntityAccessCheck.
Namespace
Drupal\Core\EntityView source
class EntityAccessCheck implements AccessInterface {
/**
* Checks access to the entity operation on the given route.
*
* The value of the '_entity_access' key must be in the pattern
* 'entity_type.operation.' The entity type must match the {entity_type}
* parameter in the route pattern. This will check a node for 'update' access:
* @code
* pattern: '/foo/{node}/bar'
* requirements:
* _entity_access: 'node.update'
* @endcode
* Available operations are 'view', 'update', 'create', and 'delete'.
*
* @param \Symfony\Component\Routing\Route $route
* The route to check against.
* @param \Drupal\Core\Routing\RouteMatchInterface $route_match
* The parametrized route
* @param \Drupal\Core\Session\AccountInterface $account
* The currently logged in account.
*
* @return \Drupal\Core\Access\AccessResultInterface
* The access result.
*/
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);
// If there is valid entity of the given entity type, check its access.
$parameters = $route_match
->getParameters();
if ($parameters
->has($entity_type)) {
$entity = $parameters
->get($entity_type);
if ($entity instanceof EntityInterface) {
return $entity
->access($operation, $account, TRUE);
}
}
// No opinion, so other access checks should decide if access should be
// allowed or not.
return AccessResult::neutral();
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
EntityAccessCheck:: |
public | function | Checks access to the entity operation on the given route. |