public function MaestroTemplateBuilderForm::removeTaskComplete in Maestro 8.2
Same name and namespace in other branches
- 3.x modules/maestro_template_builder/src/Form/MaestroTemplateBuilderForm.php \Drupal\maestro_template_builder\Form\MaestroTemplateBuilderForm::removeTaskComplete()
Ajax callback to remove a task from the template.
File
- modules/
maestro_template_builder/ src/ Form/ MaestroTemplateBuilderForm.php, line 180
Class
Namespace
Drupal\maestro_template_builder\FormCode
public function removeTaskComplete(array &$form, FormStateInterface $form_state) {
$taskToRemove = $form_state
->getValue('task_clicked');
$templateMachineName = $form_state
->getValue('template_machine_name');
$response = new AjaxResponse();
if ($taskToRemove == 'start') {
// can't delete the start task!
$response
->addCommand(new FireJavascriptCommand('maestroSignalError', [
'message' => t('You are not able to delete a Start task'),
]));
return $response;
}
$returnValue = MaestroEngine::removeTemplateTask($templateMachineName, $taskToRemove);
if ($returnValue === FALSE) {
$response
->addCommand(new FireJavascriptCommand('maestroSignalError', [
'message' => t('There was an error removing the Task. Unable to Complete the removal'),
]));
return $response;
}
else {
MaestroEngine::setTemplateToUnvalidated($templateMachineName);
$response
->addCommand(new FireJavascriptCommand('signalValidationRequired', []));
$response
->addCommand(new FireJavascriptCommand('maestroRemoveTask', [
'task' => $taskToRemove,
]));
return $response;
}
}