You are here

public function MaestroTemplateBuilderForm::drawLineComplete 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::drawLineComplete()

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

File

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

Class

MaestroTemplateBuilderForm

Namespace

Drupal\maestro_template_builder\Form

Code

public function drawLineComplete(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['nextstep']);
  if (!array_search($taskTo, $nextsteps)) {

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

    // 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;
}