class GenericGuard in State Machine 8
Hierarchy
- class \Drupal\state_machine_test\Guard\GenericGuard implements GuardInterface
Expanded class hierarchy of GenericGuard
1 string reference to 'GenericGuard'
- state_machine_test.services.yml in tests/
modules/ state_machine_test/ state_machine_test.services.yml - tests/modules/state_machine_test/state_machine_test.services.yml
1 service uses GenericGuard
- state_machine_test.generic_guard in tests/
modules/ state_machine_test/ state_machine_test.services.yml - Drupal\state_machine_test\Guard\GenericGuard
File
- tests/
modules/ state_machine_test/ src/ Guard/ GenericGuard.php, line 11
Namespace
Drupal\state_machine_test\GuardView source
class GenericGuard implements GuardInterface {
/**
* The current user.
*
* @var \Drupal\Core\Session\AccountInterface
*/
protected $currentUser;
/**
* Constructs a new GenericGuard object.
*
* @param \Drupal\Core\Session\AccountInterface $current_user
* The current user.
*/
public function __construct(AccountInterface $current_user) {
$this->currentUser = $current_user;
}
/**
* {@inheritdoc}
*/
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());
}
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
GenericGuard:: |
protected | property | The current user. | |
GenericGuard:: |
public | function |
Checks whether the given transition is allowed. Overrides GuardInterface:: |
|
GenericGuard:: |
public | function | Constructs a new GenericGuard object. |