You are here

public function FulfillmentGuard::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/FulfillmentGuard.php, line 15

Class

FulfillmentGuard

Namespace

Drupal\state_machine_test\Guard

Code

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

  // Don't allow entities in fulfillment to be cancelled.
  if ($transition
    ->getId() == 'cancel' && $entity->field_state
    ->first()->value == 'fulfillment') {
    return FALSE;
  }
}