public function MaestroIfTask::getTaskEditForm in Maestro 8.2
Same name and namespace in other branches
- 3.x src/Plugin/EngineTasks/MaestroIfTask.php \Drupal\maestro\Plugin\EngineTasks\MaestroIfTask::getTaskEditForm()
Method to allow a task to add their own fields to the task edit form.
Parameters
array $task: This is the array representation of the task from the configuration entity.
string $templateMachineName: The Maestro template machine name.
Return value
array Array Must return form declaration fields for the task editor
Overrides MaestroEngineTaskInterface::getTaskEditForm
File
- src/
Plugin/ EngineTasks/ MaestroIfTask.php, line 208
Class
- MaestroIfTask
- Maestro If Task Plugin.
Namespace
Drupal\maestro\Plugin\EngineTasksCode
public function getTaskEditForm(array $task, $templateMachineName) {
$ifParms = isset($task['data']['if']) ? $task['data']['if'] : [];
$form = [
'#markup' => $this
->t('Edit the logic for this IF task'),
];
$form['method'] = [
'#type' => 'radios',
'#title' => $this
->t('Execute the IF:'),
'#options' => [
'byvariable' => $this
->t('By Variable'),
'bylasttaskstatus' => $this
->t('By Last Task Status'),
],
'#default_value' => isset($ifParms['method']) ? $ifParms['method'] : '',
'#required' => TRUE,
'#attributes' => [
// 'onclick' => 'document.getElementById("byvar").setAttribute("open", "open");'
'onclick' => 'maestro_if_task_toggle(this);',
],
'#attached' => [
'library' => [
'maestro/maestro-engine-task-edit',
],
],
];
/*
* By Variable options
*/
$variables = MaestroEngine::getTemplateVariables($templateMachineName);
$options = [];
foreach ($variables as $variableName => $arr) {
$options[$variableName] = $variableName;
}
$form['byvariable'] = [
'#id' => 'byvar',
'#tree' => TRUE,
'#type' => 'details',
'#title' => $this
->t('By Variable Options'),
'#open' => FALSE,
];
$form['byvariable']['variable'] = [
'#type' => 'select',
'#title' => $this
->t('Argument variable'),
'#required' => FALSE,
'#default_value' => isset($ifParms['variable']) ? $ifParms['variable'] : '',
'#options' => $options,
];
$form['byvariable']['operator'] = [
'#type' => 'select',
'#title' => $this
->t('Operator'),
'#required' => FALSE,
'#default_value' => isset($ifParms['operator']) ? $ifParms['operator'] : '',
'#options' => [
'=' => '=',
'>' => '>',
'<' => '<',
'!=' => '!=',
],
];
$form['byvariable']['variable_value'] = [
'#type' => 'textfield',
'#title' => $this
->t('Variable value'),
'#description' => $this
->t('The IF will check against this value during execution'),
'#default_value' => isset($ifParms['variable_value']) ? $ifParms['variable_value'] : '',
'#required' => FALSE,
];
/*
* The by status section
*/
$form['bystatus'] = [
'#id' => 'bystatus',
'#tree' => TRUE,
'#type' => 'details',
'#title' => $this
->t('By Last Task Status'),
'#open' => FALSE,
'#markup' => $this
->t('This method is only useful if ONLY ONE task points to this IF.
If more than one task points to this IF task, a FALSE will be returned if ANY of those
tasks do not have a status of the status chosen in the status selector.'),
];
$form['bystatus']['status'] = [
'#type' => 'select',
'#title' => $this
->t('Status'),
'#required' => FALSE,
'#default_value' => isset($ifParms['status']) ? $ifParms['status'] : '',
'#options' => [
TASK_STATUS_SUCCESS => $this
->t('Last Task Status is Success'),
TASK_STATUS_CANCEL => $this
->t('Last Task Status is Cancel'),
TASK_STATUS_HOLD => $this
->t('Last Task Status is Hold'),
TASK_STATUS_ABORTED => $this
->t('Last Task Status is Aborted'),
],
];
if (isset($ifParms['method']) && $ifParms['method'] == 'byvariable') {
$form['byvariable']['#open'] = TRUE;
$form['bystatus']['#open'] = FALSE;
}
else {
$form['byvariable']['#open'] = FALSE;
$form['bystatus']['#open'] = TRUE;
}
return $form;
}