protected function BackgroundImageAccessControlHandler::checkAccess in Background Image 2.0.x
Same name and namespace in other branches
- 8 src/BackgroundImageAccessControlHandler.php \Drupal\background_image\BackgroundImageAccessControlHandler::checkAccess()
- 2.x src/BackgroundImageAccessControlHandler.php \Drupal\background_image\BackgroundImageAccessControlHandler::checkAccess()
Link the activities to the permissions. checkAccess is called with the $operation as defined in the routing.yml file.
Overrides EntityAccessControlHandler::checkAccess
File
- src/
BackgroundImageAccessControlHandler.php, line 23
Class
- BackgroundImageAccessControlHandler
- Access controller for the Background Image entity.
Namespace
Drupal\background_imageCode
protected function checkAccess(EntityInterface $entity, $operation, AccountInterface $account) {
/** @type \Drupal\background_image\Entity\BackgroundImage $entity */
switch ($operation) {
case 'view':
return AccessResult::allowedIfHasPermission($account, 'view background image');
case 'edit':
case 'update':
if ($entity
->getOwnerId() === $account
->id()) {
return AccessResult::allowedIfHasPermission($account, 'edit own background image')
->orIf(AccessResult::allowedIfHasPermission($account, 'edit background image'));
}
return AccessResult::allowedIfHasPermission($account, 'edit background image');
case 'delete':
if ($entity
->getOwnerId() === $account
->id()) {
return AccessResult::allowedIfHasPermission($account, 'delete own background image')
->orIf(AccessResult::allowedIfHasPermission($account, 'delete background image'));
}
return AccessResult::allowedIfHasPermission($account, 'delete background image');
}
return AccessResult::neutral();
}