public function WorkflowTransition::isAllowed in Workflow 7
Same name and namespace in other branches
- 7.2 includes/Entity/WorkflowTransition.php \WorkflowTransition::isAllowed()
Verifies if the given transition is allowed.
- in settings
- in permissions
- by permission hooks, implemented by other modules.
Return value
string message: empty if OK, else a message for drupal_set_message.
File
- includes/
Entity/ WorkflowTransition.php, line 70 - Contains workflow\includes\Entity\WorkflowTransition.
Class
- WorkflowTransition
- Implements an actual Transition.
Code
public function isAllowed($force) {
$old_sid = $this->old_sid;
$new_sid = $this->new_sid;
$entity_type = $this->entity_type;
$entity = $this
->getEntity();
// Entity may not be loaded, yet.
$old_state = WorkflowState::load($old_sid);
// Get all states from the Workflow, or only the valid transitions for this state.
// WorkflowState::getOptions() will consider all permissions, etc.
$options = $force ? $old_state
->getWorkflow()
->getOptions() : $old_state
->getOptions($entity_type, $entity, $force);
if (!array_key_exists($new_sid, $options)) {
$t_args = array(
'%old_sid' => $old_sid,
'%new_sid' => $new_sid,
);
return $error_message = t('The transition from %old_sid to %new_sid is not allowed.', $t_args);
}
}