You are here

public function LayoutBuilderIdsConfigureSection::alterForm in Layout builder ids 8

Same name and namespace in other branches
  1. 2.0.x src/EventSubscriber/LayoutBuilderIdsConfigureSection.php \Drupal\layout_builder_ids\EventSubscriber\LayoutBuilderIdsConfigureSection::alterForm()

Alter form.

Parameters

\Drupal\hook_event_dispatcher\Event\Form\FormAlterEvent $event: The event.

File

src/EventSubscriber/LayoutBuilderIdsConfigureSection.php, line 24

Class

LayoutBuilderIdsConfigureSection
Class LayoutBuilderIdsConfigureSection.

Namespace

Drupal\layout_builder_ids\EventSubscriber

Code

public function alterForm(FormAlterEvent $event) {

  // Get the form from the event.
  $form =& $event
    ->getForm();

  // If we are on a configure section form, alter it.
  if ($form['#form_id'] == 'layout_builder_configure_section') {

    // Get the config for the section.
    $config = $event
      ->getFormState()
      ->getFormObject()
      ->getLayout()
      ->getConfiguration();

    // Add the section id to the configure form.
    $form['layout_settings']['layout_builder_id'] = [
      '#type' => 'textfield',
      '#title' => 'Section ID',
      '#weight' => 0,
      '#default_value' => $config['layout_builder_id'] ?: NULL,
      '#description' => t('Enter an ID for the section.  IDs can contain letters, numbers, underscore, hyphen and period characters, and should start with a letter.'),
    ];

    // Add our custom submit handler.
    array_unshift($form['#submit'], [
      $this,
      'LayoutBuilderIdsSubmitForm',
    ]);
  }
}