protectedfunctioncheckAccess(EntityInterface $entity, $operation, AccountInterface $account){ /** @var \Drupal\workflows\Entity\Workflow $entity */ $workflow_type = $entity->getTypePlugin(); if(str_starts_with($operation, 'delete-state')){ [, $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); }