You are here

protected function YamlFormDialogTrait::buildDialog in YAML Form 8

Add modal dialog support to a form.

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 with modal dialog support.

3 calls to YamlFormDialogTrait::buildDialog()
YamlFormEntityForm::buildForm in src/YamlFormEntityForm.php
Form constructor.
YamlFormHandlerFormBase::buildForm in src/Form/YamlFormHandlerFormBase.php
YamlFormUiElementFormBase::buildForm in modules/yamlform_ui/src/Form/YamlFormUiElementFormBase.php
Form constructor.

File

src/YamlFormDialogTrait.php, line 43

Class

YamlFormDialogTrait
Trait class form dialogs.

Namespace

Drupal\yamlform

Code

protected function buildDialog(array &$form, FormStateInterface $form_state) {
  if ($this
    ->isModalDialog()) {
    $form['actions']['submit']['#ajax'] = [
      'callback' => '::submitForm',
      'event' => 'click',
    ];
    $form['#attached']['library'][] = 'core/drupal.dialog.ajax';
    $form['#prefix'] = '<div id="yamlform-dialog">';
    $form['#suffix'] = '</div>';
  }
  return $form;
}