function ConfigureBlockFormBase::doBuildForm

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

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.

\Drupal\layout_builder\SectionComponent $component: The section component containing the block.

Return value

array The form array.

2 calls to ConfigureBlockFormBase::doBuildForm()
AddBlockForm::buildForm in core/modules/layout_builder/src/Form/AddBlockForm.php
Builds the form for the block.
UpdateBlockForm::buildForm in core/modules/layout_builder/src/Form/UpdateBlockForm.php
Builds the block form.

File

core/modules/layout_builder/src/Form/ConfigureBlockFormBase.php, line 163

Class

ConfigureBlockFormBase
Provides a base form for configuring a block.

Namespace

Drupal\layout_builder\Form

Code

public function doBuildForm(array $form, FormStateInterface $form_state, ?SectionStorageInterface $section_storage = NULL, $delta = NULL, ?SectionComponent $component = NULL) {
    $this->sectionStorage = $section_storage;
    $this->delta = $delta;
    $this->uuid = $component->getUuid();
    $this->block = $component->getPlugin();
    $form_state->setTemporaryValue('gathered_contexts', $this->getPopulatedContexts($section_storage));
    $form['#tree'] = TRUE;
    $form['settings'] = [];
    $subform_state = SubformState::createForSubform($form['settings'], $form, $form_state);
    $form['settings'] = $this->getPluginForm($this->block)
        ->buildConfigurationForm($form['settings'], $subform_state);
    $form['actions']['submit'] = [
        '#type' => 'submit',
        '#value' => $this->submitLabel(),
        '#button_type' => 'primary',
    ];
    if ($this->isAjax()) {
        $form['actions']['submit']['#ajax']['callback'] = '::ajaxSubmit';
        // @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']);
    }
    // Mark this as an administrative page for JavaScript ("Back to site" link).
    $form['#attached']['drupalSettings']['path']['currentPathIsAdmin'] = TRUE;
    return $form;
}

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