You are here

FulfillmentGuard.php in State Machine 8

File

tests/modules/state_machine_test/src/Guard/FulfillmentGuard.php
View source
<?php

namespace Drupal\state_machine_test\Guard;

use Drupal\state_machine\Guard\GuardInterface;
use Drupal\state_machine\Plugin\Workflow\WorkflowInterface;
use Drupal\state_machine\Plugin\Workflow\WorkflowTransition;
use Drupal\Core\Entity\EntityInterface;
class FulfillmentGuard implements GuardInterface {

  /**
   * {@inheritdoc}
   */
  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;
    }
  }

}

Classes

Namesort descending Description
FulfillmentGuard