function maestro_webform_form_alter in Maestro 3.x
Same name and namespace in other branches
- 8.2 modules/maestro_webform/maestro_webform.module \maestro_webform_form_alter()
Implements hook_form_alter().
File
- modules/
maestro_webform/ maestro_webform.module, line 45 - Contains maestro_webform.module.
Code
function maestro_webform_form_alter(&$form, FormStateInterface $form_state, $form_id) {
$queueID = intval(\Drupal::request()->query
->get('queueid', 0));
$isMaestro = intval(\Drupal::request()->query
->get('maestro', 0));
// Both these keys need to exist.
if ($isMaestro && $queueID) {
$templateTask = MaestroEngine::getTemplateTaskByQueueID($queueID);
// We only care about Maestro Webform tasks.
if ($templateTask && $templateTask['tasktype'] == 'MaestroWebform') {
$storage = $form_state
->getStorage();
if ($storage && array_key_exists('form_display', $storage)) {
$webformTypes = \Drupal::entityTypeManager()
->getStorage('node_type')
->loadMultiple();
$thisForm = $storage['form_display']
->get('bundle');
$targetEntityType = $storage['form_display']
->get('targetEntityType');
if ($isMaestro == 1 && $targetEntityType == 'webform_submission' && $templateTask['data']['webform_machine_name'] == $thisForm) {
// We now know this is a webform submission. We are going to add in our own form fields here.
$form['maestro'] = [
'#tree' => TRUE,
];
$form['maestro']['type'] = [
'#type' => 'hidden',
'#default_value' => $thisForm,
'#required' => TRUE,
];
$form['maestro']['queue_id'] = [
'#type' => 'hidden',
'#default_value' => $queueID,
'#required' => TRUE,
];
$form['maestro']['process_id'] = [
'#type' => 'hidden',
'#default_value' => MaestroEngine::getProcessIdFromQueueId($queueID),
'#required' => TRUE,
];
$form['actions']['submit']['#submit'][] = 'maestro_webform_webform_type_task_submit';
}
}
}
}
}