You are here

public function MaestroWebformTask::handleExecuteSubmit in Maestro 8.2

Same name and namespace in other branches
  1. 3.x modules/maestro_webform/src/Plugin/EngineTasks/MaestroWebformTask.php \Drupal\maestro_webform\Plugin\EngineTasks\MaestroWebformTask::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

modules/maestro_webform/src/Plugin/EngineTasks/MaestroWebformTask.php, line 237

Class

MaestroWebformTask
Maestro Webform Task Plugin.

Namespace

Drupal\maestro_webform\Plugin\EngineTasks

Code

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

    // Complete the task, but we'll also flag it as TASK_STATUS_CANCEL
    // Let the devs manage the submission as well:
    \Drupal::moduleHandler()
      ->invokeAll('maestro_webform_submission_set_cancel_completion_status', [
      $queueID,
      &$form,
      &$form_state,
      $triggeringElement,
      &$completeTask,
    ]);
    if ($completeTask) {
      MaestroEngine::completeTask($queueID, \Drupal::currentUser()
        ->id());
      MaestroEngine::setTaskStatus($queueID, TASK_STATUS_CANCEL);
    }
  }

  // Redirect based on where the task told us to go.
  if (isset($templateTask['data']['redirect_to']) && $templateTask['data']['redirect_to'] != '') {
    $response = new TrustedRedirectResponse('/' . $templateTask['data']['redirect_to']);
    $form_state
      ->setResponse($response);
  }
  else {
    $response = new TrustedRedirectResponse('/taskconsole');
    $form_state
      ->setResponse($response);
  }

  // Let the devs manage the submission as well:
  \Drupal::moduleHandler()
    ->invokeAll('maestro_webform_submission_form_submit', [
    $queueID,
    &$form,
    &$form_state,
    $triggeringElement,
  ]);
}