You are here

public function MaestroInteractiveTask::handleExecuteSubmit in Maestro 3.x

Same name and namespace in other branches
  1. 8.2 src/Plugin/EngineTasks/MaestroInteractiveTask.php \Drupal\maestro\Plugin\EngineTasks\MaestroInteractiveTask::handleExecuteSubmit()

Interactive tasks, or tasks that signal themselves as requiring human interaction will have the resulting form submissions sent to their own handler for processing to determine if the task should be completed or not or to carry out any task processing that may have to be done.

Overrides MaestroEngineTaskInterface::handleExecuteSubmit

File

src/Plugin/EngineTasks/MaestroInteractiveTask.php, line 143

Class

MaestroInteractiveTask
Maestro Interactive Task Plugin.

Namespace

Drupal\maestro\Plugin\EngineTasks

Code

public function handleExecuteSubmit(array &$form, FormStateInterface $form_state) {
  $queueID = intval($form_state
    ->getValue('maestro_queue_id'));
  $canExecute = MaestroEngine::canUserExecuteTask($queueID, \Drupal::currentUser()
    ->id());
  $triggeringElement = $form_state
    ->getTriggeringElement();
  if (strstr($triggeringElement['#id'], 'edit-submit') !== FALSE && $queueID > 0 && $canExecute) {
    MaestroEngine::completeTask($queueID, \Drupal::currentUser()
      ->id());
  }
  elseif ($canExecute) {

    // we'll complete the task, but we'll also flag it as TASK_STATUS_CANCEL.
    MaestroEngine::completeTask($queueID, \Drupal::currentUser()
      ->id());
    MaestroEngine::setTaskStatus($queueID, TASK_STATUS_CANCEL);
  }
  else {

    //Note this as an exception? The user tried to complete without being assigned.
  }
  $task = MaestroEngine::getTemplateTaskByQueueID($queueID);
  if (isset($task['data']['redirect_to'])) {
    $response = new TrustedRedirectResponse($task['data']['redirect_to']);
    $form_state
      ->setResponse($response);
  }
}