public function WorkflowTransition::isValid in Workflow 8
Determines if the Transition is valid and can be executed.
@todo Add to isAllowed() ? @todo Add checks to WorkflowTransitionElement ?
Return value
bool
1 call to WorkflowTransition::isValid()
- WorkflowTransition::execute in src/
Entity/ WorkflowTransition.php - Execute a transition (change state of an entity).
File
- src/
Entity/ WorkflowTransition.php, line 325
Class
- WorkflowTransition
- Implements an actual, executed, Transition.
Namespace
Drupal\workflow\EntityCode
public function isValid() {
// Load the entity, if not already loaded.
// This also sets the (empty) $revision_id in Scheduled Transitions.
$entity = $this
->getTargetEntity();
if (!$entity) {
// @todo There is a watchdog error, but no UI-error. Is this OK?
$message = 'User tried to execute a Transition without an entity.';
$this
->logError($message);
return FALSE;
// <-- exit !!!
}
if (!$this
->getFromState()) {
// @todo The page is not correctly refreshed after this error.
$message = $this
->t('You tried to set a Workflow State, but
the entity is not relevant. Please contact your system administrator.');
$this
->messenger()
->addError($message);
$message = 'Setting a non-relevant Entity from state %sid1 to %sid2';
$this
->logError($message);
return FALSE;
// <-- exit !!!
}
// The transition is OK.
return TRUE;
}