function AddBlockForm::buildForm

Same name in other branches
  1. 9 core/modules/layout_builder/src/Form/AddBlockForm.php \Drupal\layout_builder\Form\AddBlockForm::buildForm()
  2. 10 core/modules/layout_builder/src/Form/AddBlockForm.php \Drupal\layout_builder\Form\AddBlockForm::buildForm()
  3. 11.x core/modules/layout_builder/src/Form/AddBlockForm.php \Drupal\layout_builder\Form\AddBlockForm::buildForm()

Builds the form for the block.

Parameters

array $form: An associative array containing the structure of the form.

\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.

\Drupal\layout_builder\SectionStorageInterface $section_storage: The section storage being configured.

int $delta: The delta of the section.

string $region: The region of the block.

string|null $plugin_id: The plugin ID of the block to add.

Return value

array The form array.

Overrides FormInterface::buildForm

File

core/modules/layout_builder/src/Form/AddBlockForm.php, line 53

Class

AddBlockForm
Provides a form to add a block.

Namespace

Drupal\layout_builder\Form

Code

public function buildForm(array $form, FormStateInterface $form_state, SectionStorageInterface $section_storage = NULL, $delta = NULL, $region = NULL, $plugin_id = NULL) {
    // Only generate a new component once per form submission.
    if (!($component = $form_state->get('layout_builder__component'))) {
        $component = new SectionComponent($this->uuidGenerator
            ->generate(), $region, [
            'id' => $plugin_id,
        ]);
        $section_storage->getSection($delta)
            ->appendComponent($component);
        $form_state->set('layout_builder__component', $component);
    }
    $form['#attributes']['data-layout-builder-target-highlight-id'] = $this->blockAddHighlightId($delta, $region);
    return $this->doBuildForm($form, $form_state, $section_storage, $delta, $component);
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.