public function WebformDevelEntityFormApiTestForm::buildForm in Webform 6.x
Same name and namespace in other branches
- 8.5 modules/webform_devel/src/Form/WebformDevelEntityFormApiTestForm.php \Drupal\webform_devel\Form\WebformDevelEntityFormApiTestForm::buildForm()
Form constructor.
Parameters
array $form: An associative array containing the structure of the form.
\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.
Return value
array The form structure.
Overrides EntityForm::buildForm
File
- modules/
webform_devel/ src/ Form/ WebformDevelEntityFormApiTestForm.php, line 20
Class
- WebformDevelEntityFormApiTestForm
- Export a webform's element to Form API (FAPI).
Namespace
Drupal\webform_devel\FormCode
public function buildForm(array $form, FormStateInterface $form_state) {
/** @var \Drupal\webform\WebformInterface $webform */
$webform = $this
->getEntity();
$elements = $webform
->getElementsDecoded();
// Cleanup element and set default data for testing.
$this
->cleanupElements($elements);
$this
->setDefaultValues($elements);
// Process elements and replace tokens.
$this->elementManager
->processElements($elements);
$elements = $this->tokenManager
->replace($elements);
// Set elements.
$form += $elements;
// Append submit actions.
$form['actions'] = [
'#type' => 'actions',
'#tree' => TRUE,
'submit' => [
'#type' => 'submit',
'#value' => $this
->t('Test'),
'#button_type' => 'primary',
],
];
// Attach the webform library.
$form['#attached']['library'][] = 'webform/webform.form';
// Autofocus: Save details open/close state.
$form['#attributes']['class'][] = 'js-webform-autofocus';
$form['#attached']['library'][] = 'webform/webform.form.auto_focus';
// Unsaved: Warn users about unsaved changes.
$form['#attributes']['class'][] = 'js-webform-unsaved';
$form['#attached']['library'][] = 'webform/webform.form.unsaved';
// Details save: Attach details element save open/close library.
$form['#attached']['library'][] = 'webform/webform.element.details.save';
// Details toggle: Display collapse/expand all details link.
$form['#attributes']['class'][] = 'js-webform-details-toggle';
$form['#attributes']['class'][] = 'webform-details-toggle';
$form['#attached']['library'][] = 'webform/webform.element.details.toggle';
return $this
->buildDialogConfirmForm($form, $form_state);
}