You are here

class FormAlter in Layout Builder UX 8

Alters forms, delegated by hook_form_alter() implementations.

Hierarchy

Expanded class hierarchy of FormAlter

1 file declares its use of FormAlter
lb_ux.module in ./lb_ux.module
Contains lb_ux.module.

File

src/Form/FormAlter.php, line 12

Namespace

Drupal\lb_ux\Form
View source
class FormAlter {
  use AjaxHelperTrait;

  /**
   * Alters the section configuration form.
   *
   * @param array $form
   *   An associative array containing the structure of the form.
   * @param \Drupal\Core\Form\FormStateInterface $form_state
   *   The current state of the form.
   */
  public function alterConfigureForm(array &$form, FormStateInterface $form_state) {
    if ($this
      ->isAjax()) {

      // Allow the forms loaded into off-canvas to display status messages.
      if (!isset($form['status_messages'])) {
        $form['status_messages'] = [
          '#type' => 'status_messages',
        ];
      }

      // @todo 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. Remove this
      //   workaround in https://www.drupal.org/node/2897377.
      $form['#id'] = Html::getId($form_state
        ->getBuildInfo()['form_id']);
    }
  }

}

Members

Namesort descending Modifiers Type Description Overrides
AjaxHelperTrait::getRequestWrapperFormat protected function Gets the wrapper format of the current request.
AjaxHelperTrait::isAjax protected function Determines if the current request is via AJAX.
FormAlter::alterConfigureForm public function Alters the section configuration form.