You are here

function maestro_maestro_template_validation_check in Maestro 3.x

Same name and namespace in other branches
  1. 8.2 maestro.module \maestro_maestro_template_validation_check()

Implements hook_maestro_template_validation_check().

File

./maestro.module, line 361
Provides glue logic, hook implementation and core set process variable functions.

Code

function maestro_maestro_template_validation_check($templateMachineName, &$validation_failure_tasks, &$validation_information_tasks) {

  // For our purposes, we will check to see if the template has any tasks that are set to have status turned on even though we have the
  // number of status stages set to 0.
  // Also check for tasks with a status number of 0.
  $notice = [];
  $taskStatusIsSet = FALSE;
  $templateStatusIsOn = FALSE;
  $template = MaestroEngine::getTemplate($templateMachineName);
  if (isset($template->default_workflow_timeline_stage_count) && $template->default_workflow_timeline_stage_count > 0) {
    $templateStatusIsOn = TRUE;
  }
  foreach ($template->tasks as $task) {
    if (isset($task['participate_in_workflow_status_stage']) && $task['participate_in_workflow_status_stage'] == TRUE) {
      $taskStatusIsSet = TRUE;
      if (isset($task['workflow_status_stage_number']) && $task['workflow_status_stage_number'] == 0) {
        $validation_information_tasks[] = [
          'taskID' => $task['id'],
          'taskLabel' => $task['label'],
          'reason' => t('The task is set to participate in the setting of status messages, however,
              the task has 0 set for the task stage.  This will not set any status stage message.'),
        ];
      }
    }
  }
  if (!$templateStatusIsOn && $taskStatusIsSet) {

    // Make our template warning first.
    $notice[] = [
      'taskID' => t('Entire Template'),
      'taskLabel' => t('Entire Template'),
      'reason' => t('The template has the "The default number of stages you wish to show this workflow having" option set to 0,
          however, there are tasks that set status. This will cause no status to show for newly spawned processes of this template.'),
    ];
    $validation_information_tasks = array_merge($notice, $validation_information_tasks);
  }
}