public function MaestroTrace::submitForm in Maestro 3.x
Same name and namespace in other branches
- 8.2 src/Form/MaestroTrace.php \Drupal\maestro\Form\MaestroTrace::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/ MaestroTrace.php, line 260
Class
- MaestroTrace
- Maestro Trace functionality form.
Namespace
Drupal\maestro\FormCode
public function submitForm(array &$form, FormStateInterface $form_state) {
$triggering_element = $form_state
->getTriggeringElement();
if ($triggering_element and isset($triggering_element['#name']) and $triggering_element['#name'] == 'deleteprocess') {
$tasks = $form_state
->getValue('tasks_table');
$deleteItems = [];
foreach ($tasks as $queueID => $task) {
$deleteItems[] = $queueID;
}
$form_state
->setRedirect('maestro.delete.process', [
'processID' => $form_state
->getValue('process_id'),
'idList' => implode(',', $deleteItems),
]);
}
else {
// We are now going to skim through the list of variables and update their values if the changed flag is set.
// This will hold all of the items that should be deleted.
$deleteItems = [];
$variables = $form_state
->getValue('vars_table');
foreach ($variables as $variableID => $variable) {
if ($variable['change'] == 1) {
// Set the process variable here.
$varRecord = \Drupal::entityTypeManager()
->getStorage('maestro_process_variables')
->resetCache([
$variableID,
]);
$varRecord = \Drupal::entityTypeManager()
->getStorage('maestro_process_variables')
->load($variableID);
$varRecord
->set('variable_value', $variable['variable_value']);
$varRecord
->save();
}
}
// Now do the same for the tasks.
$tasks = $form_state
->getValue('tasks_table');
foreach ($tasks as $queueID => $task) {
if ($task['change'] == 1) {
$queueRecord = MaestroEngine::getQueueEntryById($queueID);
// First check if this should be deleted. if so, don't bother with any updates.
if ($task['delete'] == 1) {
// $queueRecord->delete();
$deleteItems[] = $queueID;
}
else {
// Set the queue item's values for status and archived here.
$queueRecord
->set('status', $task['status']);
$queueRecord
->set('archived', $task['archived']);
$queueRecord
->save();
}
}
}
// Now handle the deleted items via a confirm form.
if (count($deleteItems) > 0) {
$form_state
->setRedirect('maestro.delete.task', [
'processID' => $form_state
->getValue('process_id'),
'idList' => implode(',', $deleteItems),
]);
}
}
}