You are here

public function MaestroContentTypeCompleteTask::submitForm in Maestro 3.x

Same name and namespace in other branches
  1. 8.2 src/Form/MaestroContentTypeCompleteTask.php \Drupal\maestro\Form\MaestroContentTypeCompleteTask::submitForm()

Form submission handler.

Parameters

array $form: An associative array containing the structure of the form.

\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.

Overrides FormInterface::submitForm

File

src/Form/MaestroContentTypeCompleteTask.php, line 65

Class

MaestroContentTypeCompleteTask
Implements the complete task form for content type tasks when viewing.

Namespace

Drupal\maestro\Form

Code

public function submitForm(array &$form, FormStateInterface $form_state) {
  $queueID = $form_state
    ->getValue('queueid', 0);
  $triggeringElement = $form_state
    ->getTriggeringElement();
  isset($task['data']['redirect_to']) && $task['data']['redirect_to'] != '' ? $base_redirect_url = $task['data']['redirect_to'] : ($base_redirect_url = '/');
  if ($queueID) {
    $task = MaestroEngine::getTemplateTaskByQueueID($queueID);

    // Just a failsafe.
    if ($task['tasktype'] == 'MaestroContentType' && MaestroEngine::canUserExecuteTask($queueID, \Drupal::currentUser()
      ->id())) {
      if (strstr($triggeringElement['#id'], 'edit-submit') !== FALSE && $queueID > 0) {
        MaestroEngine::completeTask($queueID, \Drupal::currentUser()
          ->id());
        isset($task['data']['accept_redirect_to']) && $task['data']['accept_redirect_to'] != '' ? $redirect_url = $task['data']['accept_redirect_to'] : ($redirect_url = $base_redirect_url);
      }
      else {

        // 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);
        $redirect_url = isset($task['data']['reject_redirect_to']) && $task['data']['reject_redirect_to'] != '' ? $redirect_url = $task['data']['reject_redirect_to'] : ($redirect_url = $base_redirect_url);
      }
    }
    if (isset($task['data']['supply_maestro_ids_in_url']) && $task['data']['supply_maestro_ids_in_url'] == 1) {
      $url = Url::fromUserInput($redirect_url, [
        'query' => [
          'maestro' => 1,
          'queueid' => $form_state
            ->getValue('queueid', 0),
        ],
      ]);
    }
    else {
      $url = Url::fromUserInput($redirect_url);
    }
    $form_state
      ->setRedirectUrl($url);
  }
}