public function Workflow::isValid in Workflow 7.2
Validate the workflow. Generate a message if not correct.
This function is used on the settings page of:
- Workflow node: workflow_admin_ui_type_map_form()
- Workflow field: WorkflowItem->settingsForm()
Return value
bool $is_valid
Overrides WorkflowInterface::isValid
File
- includes/
Entity/ Workflow.php, line 261 - Contains workflow\includes\Entity\Workflow. Contains workflow\includes\Entity\WorkflowController.
Class
Code
public function isValid() {
$is_valid = TRUE;
$workflow_name = $this
->getName();
$wid = $this
->getWorkflowId();
// Don't allow workflows with no states. There should always be a creation state.
$states = $this
->getStates($all = FALSE);
if (count($states) < 1) {
// That's all, so let's remind them to create some states.
$message = t('Workflow %workflow has no states defined, so it cannot be assigned to content yet.', array(
'%workflow' => $workflow_name,
));
drupal_set_message($message, 'warning');
// Skip allowing this workflow.
$is_valid = FALSE;
}
// Also check for transitions, at least out of the creation state. Use 'ALL' role.
$transitions = $this
->getTransitionsBySid($this
->getCreationSid(), $roles = 'ALL');
if (count($transitions) < 1) {
// That's all, so let's remind them to create some transitions.
$message = t('Workflow %workflow has no transitions defined, so it cannot be assigned to content yet.', array(
'%workflow' => $workflow_name,
));
drupal_set_message($message, 'warning');
// Skip allowing this workflow.
$is_valid = FALSE;
}
// If the Workflow is mapped to a node type, check if workflow->options is set.
if ($this
->getTypeMap() && !count($this->options)) {
// That's all, so let's remind them to create some transitions.
$message = t('Please maintain Workflow %workflow on its <a href="@url">settings</a> page.', array(
'%workflow' => $this
->getName(),
'@url' => url(WORKFLOW_ADMIN_UI_PATH . "/manage/{$wid}"),
));
drupal_set_message($message, 'warning');
// Skip allowing this workflow.
// $is_valid = FALSE;
}
return $is_valid;
}