You are here

public function MaestroTemplateBuilderForm::drawFalseLineComplete in Maestro 3.x

Same name and namespace in other branches
  1. 8.2 modules/maestro_template_builder/src/Form/MaestroTemplateBuilderForm.php \Drupal\maestro_template_builder\Form\MaestroTemplateBuilderForm::drawFalseLineComplete()

Ajax callback to complete the false line drawing routine when the second task has been selected.

File

modules/maestro_template_builder/src/Form/MaestroTemplateBuilderForm.php, line 149

Class

MaestroTemplateBuilderForm

Namespace

Drupal\maestro_template_builder\Form

Code

public function drawFalseLineComplete(array &$form, FormStateInterface $form_state) {
  $taskFrom = $form_state
    ->getValue('task_line_from');
  $taskTo = $form_state
    ->getValue('task_line_to');
  $templateMachineName = $form_state
    ->getValue('template_machine_name');
  $template = MaestroEngine::getTemplate($templateMachineName);
  $templateTaskFrom = MaestroEngine::getTemplateTaskByID($templateMachineName, $taskFrom);
  $templateTaskTo = MaestroEngine::getTemplateTaskByID($templateMachineName, $taskTo);
  $nextsteps = explode(',', $templateTaskFrom['nextfalsestep']);
  if (!array_search($taskTo, $nextsteps)) {

    // Add it to the task.
    if ($templateTaskFrom['nextfalsestep'] != '') {
      $templateTaskFrom['nextfalsestep'] .= ',';
    }
    $templateTaskFrom['nextfalsestep'] .= $taskTo;
    $template->tasks[$taskFrom]['nextfalsestep'] = $templateTaskFrom['nextfalsestep'];

    // We want to force the designer to validate the template to be sure.
    $template->validated = FALSE;
    $template
      ->save();
  }
  $response = new AjaxResponse();
  $response
    ->addCommand(new FireJavascriptCommand('signalValidationRequired', []));
  $response
    ->addCommand(new FireJavascriptCommand('maestroCloseTaskMenu', []));
  return $response;
}