3 namespace Drupal\layout_builder\Form;
5 use Drupal\Core\Form\FormStateInterface;
6 use Drupal\layout_builder\SectionComponent;
7 use Drupal\layout_builder\SectionStorageInterface;
10 * Provides a form to add a block.
14 class AddBlockForm extends ConfigureBlockFormBase {
19 public function getFormId() {
20 return 'layout_builder_add_block';
26 protected function submitLabel() {
27 return $this->t('Add Block');
31 * Builds the form for the block.
34 * An associative array containing the structure of the form.
35 * @param \Drupal\Core\Form\FormStateInterface $form_state
36 * The current state of the form.
37 * @param \Drupal\layout_builder\SectionStorageInterface $section_storage
38 * The section storage being configured.
40 * The delta of the section.
41 * @param string $region
42 * The region of the block.
43 * @param string|null $plugin_id
44 * The plugin ID of the block to add.
49 public function buildForm(array $form, FormStateInterface $form_state, SectionStorageInterface $section_storage = NULL, $delta = NULL, $region = NULL, $plugin_id = NULL) {
50 // Only generate a new component once per form submission.
51 if (!$component = $form_state->get('layout_builder__component')) {
52 $component = new SectionComponent($this->uuidGenerator->generate(), $region, ['id' => $plugin_id]);
53 $section_storage->getSection($delta)->appendComponent($component);
54 $form_state->set('layout_builder__component', $component);
56 return $this->doBuildForm($form, $form_state, $section_storage, $delta, $component);