public function WebformAccessGroupAccessControlHandler::checkAccess in Webform 6.x
Same name and namespace in other branches
- 8.5 modules/webform_access/src/WebformAccessGroupAccessControlHandler.php \Drupal\webform_access\WebformAccessGroupAccessControlHandler::checkAccess()
Performs access checks.
This method is supposed to be overwritten by extending classes that do their own custom access checking.
Parameters
\Drupal\Core\Entity\EntityInterface $entity: The entity for which to check access.
string $operation: The entity operation. Usually one of 'view', 'view label', 'update' or 'delete'.
\Drupal\Core\Session\AccountInterface $account: The user for which to check access.
Return value
\Drupal\Core\Access\AccessResultInterface The access result.
Overrides EntityAccessControlHandler::checkAccess
File
- modules/
webform_access/ src/ WebformAccessGroupAccessControlHandler.php, line 20
Class
- WebformAccessGroupAccessControlHandler
- Defines the access control handler for the webform access entity type.
Namespace
Drupal\webform_accessCode
public function checkAccess(EntityInterface $entity, $operation, AccountInterface $account) {
/** @var \Drupal\webform_access\WebformAccessGroupInterface $entity */
if ($account
->hasPermission('administer webform')) {
$access_result = AccessResult::allowed();
}
elseif ($operation === 'update') {
$admin_ids = $entity
->getAdminIds();
$is_admin = $admin_ids && in_array($account
->id(), $admin_ids) ? TRUE : FALSE;
$access_result = AccessResult::allowedIf($is_admin)
->addCacheableDependency($entity);
}
else {
$access_result = AccessResult::neutral();
}
return $access_result
->addCacheableDependency($account);
}