public function MaestroWebformTask::getTaskEditForm in Maestro 8.2
Same name and namespace in other branches
- 3.x modules/maestro_webform/src/Plugin/EngineTasks/MaestroWebformTask.php \Drupal\maestro_webform\Plugin\EngineTasks\MaestroWebformTask::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
- modules/
maestro_webform/ src/ Plugin/ EngineTasks/ MaestroWebformTask.php, line 274
Class
- MaestroWebformTask
- Maestro Webform Task Plugin.
Namespace
Drupal\maestro_webform\Plugin\EngineTasksCode
public function getTaskEditForm(array $task, $templateMachineName) {
// let's get all the webforms established in the system.
$webforms = Webform::loadMultiple();
// $webforms is an array where the keys are the machine names of the webform and values are the webform entity.
// the $webform[$key]->title is the human readable name.
$webform_options = [
'' => $this
->t('Please Choose'),
];
foreach ($webforms as $key => $webform) {
$webform_options[$key] = $webform
->get('title');
}
$form['webform_machine_name'] = [
'#type' => 'select',
'#options' => $webform_options,
'#title' => $this
->t('Webform'),
'#description' => $this
->t('The Webform you wish to use when no previous submissions tagged with the Unique Identifier (next field) exist in the workflow.
If a submission exists in the workflow, this field is used to show the webform\'s output.'),
'#default_value' => isset($task['data']['webform_machine_name']) ? $task['data']['webform_machine_name'] : '',
'#required' => TRUE,
'#ajax' => [
'callback' => [
$this,
'fetchNodesAttached',
],
'event' => 'change',
'wrapper' => 'attached-nodes',
'progress' => [
'type' => 'throbber',
'message' => t('Fetching Nodes Attached...'),
],
],
];
$form['unique_id'] = [
'#type' => 'textfield',
'#title' => $this
->t('Unique Identifier'),
'#description' => $this
->t('The name of the key used when tracking the webform content for the maestro process. By default the identifier is "submission".'),
'#default_value' => isset($task['data']['unique_id']) ? $task['data']['unique_id'] : '',
'#required' => TRUE,
];
$form['show_edit_form'] = [
'#type' => 'checkbox',
'#title' => $this
->t('Show the edit form if submission already exists?'),
'#description' => $this
->t('If a webform submission already exists, checking this option will send you to the edit form for the submission rather than the summary.'),
'#default_value' => isset($task['data']['show_edit_form']) ? $task['data']['show_edit_form'] : '0',
];
$form['use_nodes_attached'] = [
'#type' => 'checkbox',
'#title' => $this
->t('Webform attached to a node?'),
'#description' => $this
->t('Is your webform attached to a node?
When checked, signals Maestro that your entry/edit of a webform depends on the node it is attached to.'),
'#default_value' => isset($task['data']['use_nodes_attached']) ? $task['data']['use_nodes_attached'] : '0',
];
$form['nodes_attached'] = [
'#type' => 'fieldset',
'#title' => $this
->t('Webform Attached to Node Settings'),
'#states' => [
'visible' => [
':input[name="use_nodes_attached"]' => [
'checked' => TRUE,
],
],
],
];
$variables = MaestroEngine::getTemplateVariables($templateMachineName);
$options = [];
$options['none'] = $this
->t('Do not use process variable');
foreach ($variables as $variableName => $arr) {
$options[$variableName] = $variableName;
}
$form['nodes_attached']['webform_nodes_attached_variable'] = [
'#type' => 'select',
'#options' => $options,
'#title' => $this
->t('Specify a variable to use that holds a Node ID.'),
'#description' => $this
->t('The variable selected must be populated by a single Node ID which the chosen webform is attached to.'),
'#default_value' => isset($task['data']['webform_nodes_attached_variable']) ? $task['data']['webform_nodes_attached_variable'] : '',
'#required' => FALSE,
'#states' => [
'visible' => [
':input[name="use_nodes_attached"]' => [
'checked' => TRUE,
],
],
],
];
// Based on the webform_machine_name, we do an auto-lookup to determine if any nodes are bound to this webform and
// allow the administrator to choose a node to use to show the webform to the end user for editing/creating.
// this alters the webform's URI when presenting add/edit pages.
$options = $this
->_getAttachedNodeOptions(isset($task['data']['webform_machine_name']) ? $task['data']['webform_machine_name'] : '');
$form['nodes_attached']['webform_nodes_attached_to'] = [
'#type' => 'select',
'#title' => $this
->t('Select a Node Attached To Specified Webform'),
'#description' => $this
->t('Enabled when you choose NOT to use a process variable. Listed are the nodes that use the specified webform.'),
'#states' => [
'enabled' => [
':input[name="webform_nodes_attached_variable"]' => [
'value' => 'none',
],
],
],
'#options' => $options,
'#default_value' => isset($task['data']['webform_nodes_attached_to']) ? $task['data']['webform_nodes_attached_to'] : 'none',
'#required' => FALSE,
'#prefix' => '<div id="attached-nodes">',
'#suffix' => '</div>',
];
$form['skip_webform_handlers'] = [
'#type' => 'checkbox',
'#title' => $this
->t('Skip Any Maestro Webform Submission Handlers'),
'#description' => $this
->t('Maestro allows you to spawn a workflow via a Webform submission handler. Check to bypass any Maestro webform submission handlers attached to the webform chosen.'),
'#default_value' => isset($task['data']['skip_webform_handlers']) ? $task['data']['skip_webform_handlers'] : '0',
];
$form['redirect_to'] = [
'#type' => 'textfield',
'#title' => $this
->t('Return Path'),
'#description' => $this
->t('You can specify where your return path should go upon task completion.'),
'#default_value' => isset($task['data']['redirect_to']) ? $task['data']['redirect_to'] : 'taskconsole',
'#required' => TRUE,
];
return $form;
}