function WorkflowAccessControlHandler::checkAccess

Same name in other branches
  1. 8.9.x core/modules/workflows/src/WorkflowAccessControlHandler.php \Drupal\workflows\WorkflowAccessControlHandler::checkAccess()
  2. 10 core/modules/workflows/src/WorkflowAccessControlHandler.php \Drupal\workflows\WorkflowAccessControlHandler::checkAccess()
  3. 11.x core/modules/workflows/src/WorkflowAccessControlHandler.php \Drupal\workflows\WorkflowAccessControlHandler::checkAccess()

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);
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.