You are here

public function GenericGuard::allowed in State Machine 8

Checks whether the given transition is allowed.

Parameters

\Drupal\state_machine\Plugin\Workflow\WorkflowTransition $transition: The transition.

\Drupal\state_machine\Plugin\Workflow\WorkflowInterface $workflow: The workflow.

\Drupal\Core\Entity\EntityInterface $entity: The parent entity.

Return value

bool TRUE if the transition is allowed, FALSE otherwise.

Overrides GuardInterface::allowed

File

tests/modules/state_machine_test/src/Guard/GenericGuard.php, line 33

Class

GenericGuard

Namespace

Drupal\state_machine_test\Guard

Code

public function allowed(WorkflowTransition $transition, WorkflowInterface $workflow, EntityInterface $entity) {

  // Only a "supervisor" user can cancel an entity in validation.
  if ($transition
    ->getId() == 'cancel' && $entity->field_state
    ->first()->value == 'validation') {
    return (bool) array_intersect([
      'merchant',
    ], $this->currentUser
      ->getRoles());
  }
}