You are here

public function BlockEntitySettingTrayForm::buildForm in Drupal 8

Same name and namespace in other branches
  1. 9 core/modules/settings_tray/src/Block/BlockEntitySettingTrayForm.php \Drupal\settings_tray\Block\BlockEntitySettingTrayForm::buildForm()
  2. 10 core/modules/settings_tray/src/Block/BlockEntitySettingTrayForm.php \Drupal\settings_tray\Block\BlockEntitySettingTrayForm::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

core/modules/settings_tray/src/Block/BlockEntitySettingTrayForm.php, line 124

Class

BlockEntitySettingTrayForm
Provides form for block instance forms when used in the off-canvas dialog.

Namespace

Drupal\settings_tray\Block

Code

public function buildForm(array $form, FormStateInterface $form_state) {
  $form = parent::buildForm($form, $form_state);
  $form['actions']['submit']['#ajax'] = [
    'callback' => '::ajaxSubmit',
  ];
  $form['#attached']['library'][] = 'core/drupal.dialog.ajax';

  // static::ajaxSubmit() requires data-drupal-selector to be the same between
  // the various Ajax requests. A bug in \Drupal\Core\Form\FormBuilder
  // prevents that from happening unless $form['#id'] is also the same.
  // Normally, #id is set to a unique HTML ID via Html::getUniqueId(), but
  // here we bypass that in order to work around the data-drupal-selector bug.
  // This is okay so long as we assume that this form only ever occurs once on
  // a page.
  // @todo Remove this workaround once https://www.drupal.org/node/2897377 is
  //   fixed.
  $form['#id'] = Html::getId($form_state
    ->getBuildInfo()['form_id']);
  return $form;
}