You are here

public function MaestroSetProcessVariableTask::getTaskEditForm in Maestro 8.2

Same name and namespace in other branches
  1. 3.x src/Plugin/EngineTasks/MaestroSetProcessVariableTask.php \Drupal\maestro\Plugin\EngineTasks\MaestroSetProcessVariableTask::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/MaestroSetProcessVariableTask.php, line 140

Class

MaestroSetProcessVariableTask
Maestro Set Process Variable Task Plugin.

Namespace

Drupal\maestro\Plugin\EngineTasks

Code

public function getTaskEditForm(array $task, $templateMachineName) {
  $spv = $task['data']['spv'];
  $form = [
    '#markup' => $this
      ->t('Editing the Process Variable Task'),
  ];
  $form['spv'] = [
    '#tree' => TRUE,
    '#type' => 'fieldset',
    '#title' => $this
      ->t('Choose which process variable you wish to set and how'),
    '#collapsed' => FALSE,
  ];
  $variables = MaestroEngine::getTemplateVariables($templateMachineName);
  $options = [];
  foreach ($variables as $variableName => $arr) {
    $options[$variableName] = $variableName;
  }
  $form['spv']['variable'] = [
    '#type' => 'select',
    '#title' => $this
      ->t('Choose the variable'),
    '#required' => TRUE,
    '#default_value' => isset($spv['variable']) ? $spv['variable'] : '',
    '#options' => $options,
  ];

  // TODO: add other options here such as the content field result
  // however, the content field result needs to be rethought on how we're leveraging content.
  $form['spv']['method'] = [
    '#type' => 'radios',
    '#title' => $this
      ->t('Method to set variable'),
    '#options' => [
      'hardcoded' => $this
        ->t('Hardcoded Value'),
      'addsubtract' => $this
        ->t('Add or Subtract a Value'),
      'bycontentfunction' => $this
        ->t('By Function. Pass "function_name:parameter1,parameter2,..." in variable
                                          as comma separated list. e.g. maestro_spv_content_value_fetch:unique_identifier,field_your_field'),
    ],
    '#default_value' => isset($spv['method']) ? $spv['method'] : '',
    '#required' => TRUE,
  ];
  $form['spv']['variable_value'] = [
    '#type' => 'textfield',
    '#title' => $this
      ->t('Variable value'),
    '#description' => $this
      ->t('The value you wish to set the variable to based on your METHOD selection above'),
    '#default_value' => isset($spv['variable_value']) ? $spv['variable_value'] : '',
    '#required' => TRUE,
  ];
  return $form;
}