You are here

public function MaestroInteractiveFormBase::buildForm in Maestro 8.2

Same name and namespace in other branches
  1. 3.x src/Form/MaestroInteractiveFormBase.php \Drupal\maestro\Form\MaestroInteractiveFormBase::buildForm()

Form constructor.

Parameters

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

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

Return value

array The form structure.

Overrides FormInterface::buildForm

1 call to MaestroInteractiveFormBase::buildForm()
MaestroExecuteInteractive::buildForm in src/Form/MaestroExecuteInteractive.php
Overridden method to build the form for the interactive task. We are fetching off the interactive function's form fields for this task. .
1 method overrides MaestroInteractiveFormBase::buildForm()
MaestroExecuteInteractive::buildForm in src/Form/MaestroExecuteInteractive.php
Overridden method to build the form for the interactive task. We are fetching off the interactive function's form fields for this task. .

File

src/Form/MaestroInteractiveFormBase.php, line 163

Class

MaestroInteractiveFormBase
The Maestro Interactive task form base.

Namespace

Drupal\maestro\Form

Code

public function buildForm(array $form, FormStateInterface $form_state, $queueid = NULL, $modal = NULL) {
  $this->queueID = $queueid;
  $this->modal = $modal;

  // Get the return path from the task definition.
  $queueRecord = \Drupal::entityTypeManager()
    ->getStorage('maestro_queue')
    ->load($queueid);
  if ($queueRecord) {
    $templateMachineName = MaestroEngine::getTemplateIdFromProcessId($queueRecord->process_id
      ->getString());
    $taskTemplate = MaestroEngine::getTemplateTaskByID($templateMachineName, $queueRecord->task_id
      ->getString());
    if (isset($taskTemplate['data']['redirect_to'])) {
      $this->returnPath = $taskTemplate['data']['redirect_to'];
    }
    else {
      $config = \Drupal::config('maestro.settings');

      // Before we do anything, determine where to redirect the user after execution:
      if ($config
        ->get('maestro_redirect_location')) {
        $this->returnPath = 'taskconsole';
      }
      else {

        // we're just going out on a limb here and returning the person back to our task console.
        $this->returnPath = 'taskconsole';
      }
    }
    $form = [];

    // Determine if this user should even be seeing this page.
    if (!MaestroEngine::canUserExecuteTask($this->queueID, \Drupal::currentUser()
      ->id())) {
      $form['error'] = [
        '#markup' => $this
          ->t('You do not have access to this task.  The task has either been reassigned or is no longer valid.'),
      ];

      // Throw new AccessDeniedHttpException(); //doing this in a modal just makes the modal hang.
    }

    // Devs can override/add to this form declaration as they see fit.
    return $form;
  }
  else {

    // There is no queue record.
    $form['error'] = [
      '#markup' => $this
        ->t('The task is no longer valid.'),
    ];
  }
}