You are here

protected function WorkflowAccessControlHandler::checkAccess in Drupal 10

Same name and namespace in other branches
  1. 8 core/modules/workflows/src/WorkflowAccessControlHandler.php \Drupal\workflows\WorkflowAccessControlHandler::checkAccess()
  2. 9 core/modules/workflows/src/WorkflowAccessControlHandler.php \Drupal\workflows\WorkflowAccessControlHandler::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

core/modules/workflows/src/WorkflowAccessControlHandler.php, line 54

Class

WorkflowAccessControlHandler
Access controller for the Workflow entity.

Namespace

Drupal\workflows

Code

protected function checkAccess(EntityInterface $entity, $operation, AccountInterface $account) {

  /** @var \Drupal\workflows\Entity\Workflow $entity */
  $workflow_type = $entity
    ->getTypePlugin();
  if (strpos($operation, 'delete-state') === 0) {
    [
      ,
      $state_id,
    ] = explode(':', $operation, 2);

    // Deleting a state is editing a workflow, but also we should forbid
    // access if there is only one state.
    return AccessResult::allowedIf(count($entity
      ->getTypePlugin()
      ->getStates()) > 1)
      ->andIf(parent::checkAccess($entity, 'edit', $account))
      ->andIf(AccessResult::allowedIf(!in_array($state_id, $workflow_type
      ->getRequiredStates(), TRUE)))
      ->addCacheableDependency($entity);
  }
  return parent::checkAccess($entity, $operation, $account);
}