protected function ScriptAccessControlHandler::checkAccess in Script Manager 8
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
- src/
Entity/ ScriptAccessControlHandler.php, line 63
Class
- ScriptAccessControlHandler
- Access control handler for script entities.
Namespace
Drupal\script_manager\EntityCode
protected function checkAccess(EntityInterface $entity, $operation, AccountInterface $account) {
/** @var \Drupal\script_manager\Entity\Script $entity */
if ($operation !== 'view') {
return parent::checkAccess($entity, $operation, $account);
}
try {
$conditions = $this
->getPreparedConditions($entity);
} catch (ContextException $e) {
// Following core blocks convention, access is uncacheable when context
// is missing.
return AccessResult::forbidden()
->setCacheMaxAge(0);
}
$access = $this
->resolveConditions($conditions, 'and') !== FALSE ? AccessResult::allowed() : AccessResult::forbidden();
// Add dependencies on all of the condition and entity cachability metadata.
$access
->addCacheableDependency($entity);
foreach ($conditions as $condition) {
if ($condition instanceof CacheableDependencyInterface) {
$access
->addCacheableDependency($condition);
}
}
return $access;
}