class StateTransitionValidation in Drupal 9
Same name and namespace in other branches
- 8 core/modules/content_moderation/src/StateTransitionValidation.php \Drupal\content_moderation\StateTransitionValidation
Validates whether a certain state transition is allowed.
Hierarchy
- class \Drupal\content_moderation\StateTransitionValidation implements StateTransitionValidationInterface
Expanded class hierarchy of StateTransitionValidation
1 file declares its use of StateTransitionValidation
- StateTransitionValidationTest.php in core/
modules/ content_moderation/ tests/ src/ Unit/ StateTransitionValidationTest.php
1 string reference to 'StateTransitionValidation'
- content_moderation.services.yml in core/
modules/ content_moderation/ content_moderation.services.yml - core/modules/content_moderation/content_moderation.services.yml
1 service uses StateTransitionValidation
- content_moderation.state_transition_validation in core/
modules/ content_moderation/ content_moderation.services.yml - Drupal\content_moderation\StateTransitionValidation
File
- core/
modules/ content_moderation/ src/ StateTransitionValidation.php, line 14
Namespace
Drupal\content_moderationView source
class StateTransitionValidation implements StateTransitionValidationInterface {
/**
* The moderation information service.
*
* @var \Drupal\content_moderation\ModerationInformationInterface
*/
protected $moderationInfo;
/**
* Stores the possible state transitions.
*
* @var array
*/
protected $possibleTransitions = [];
/**
* Constructs a new StateTransitionValidation.
*
* @param \Drupal\content_moderation\ModerationInformationInterface $moderation_info
* The moderation information service.
*/
public function __construct(ModerationInformationInterface $moderation_info) {
$this->moderationInfo = $moderation_info;
}
/**
* {@inheritdoc}
*/
public function getValidTransitions(ContentEntityInterface $entity, AccountInterface $user) {
$workflow = $this->moderationInfo
->getWorkflowForEntity($entity);
$current_state = $entity->moderation_state->value ? $workflow
->getTypePlugin()
->getState($entity->moderation_state->value) : $workflow
->getTypePlugin()
->getInitialState($entity);
return array_filter($current_state
->getTransitions(), function (Transition $transition) use ($workflow, $user) {
return $user
->hasPermission('use ' . $workflow
->id() . ' transition ' . $transition
->id());
});
}
/**
* {@inheritdoc}
*/
public function isTransitionValid(WorkflowInterface $workflow, StateInterface $original_state, StateInterface $new_state, AccountInterface $user, ContentEntityInterface $entity) {
$transition = $workflow
->getTypePlugin()
->getTransitionFromStateToState($original_state
->id(), $new_state
->id());
return $user
->hasPermission('use ' . $workflow
->id() . ' transition ' . $transition
->id());
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
StateTransitionValidation:: |
protected | property | The moderation information service. | |
StateTransitionValidation:: |
protected | property | Stores the possible state transitions. | |
StateTransitionValidation:: |
public | function |
Gets a list of transitions that are legal for this user on this entity. Overrides StateTransitionValidationInterface:: |
|
StateTransitionValidation:: |
public | function |
Checks if a transition between two states if valid for the given user. Overrides StateTransitionValidationInterface:: |
|
StateTransitionValidation:: |
public | function | Constructs a new StateTransitionValidation. |