X-Git-Url: http://www.aleph1.co.uk/gitweb/?p=yaffs-website;a=blobdiff_plain;f=web%2Fcore%2Fmodules%2Flayout_builder%2Fsrc%2FForm%2FAddBlockForm.php;fp=web%2Fcore%2Fmodules%2Flayout_builder%2Fsrc%2FForm%2FAddBlockForm.php;h=704d136ba96fc03d0b22520c16e40c6cb707a232;hp=0000000000000000000000000000000000000000;hb=af6d1fb995500ae68849458ee10d66abbdcfb252;hpb=680c79a86e3ed402f263faeac92e89fb6d9edcc0 diff --git a/web/core/modules/layout_builder/src/Form/AddBlockForm.php b/web/core/modules/layout_builder/src/Form/AddBlockForm.php new file mode 100644 index 000000000..704d136ba --- /dev/null +++ b/web/core/modules/layout_builder/src/Form/AddBlockForm.php @@ -0,0 +1,59 @@ +t('Add Block'); + } + + /** + * Builds the form for the block. + * + * @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. + * @param \Drupal\layout_builder\SectionStorageInterface $section_storage + * The section storage being configured. + * @param int $delta + * The delta of the section. + * @param string $region + * The region of the block. + * @param string|null $plugin_id + * The plugin ID of the block to add. + * + * @return array + * The form array. + */ + 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->getTemporaryValue('layout_builder__component')) { + $component = new SectionComponent($this->uuidGenerator->generate(), $region, ['id' => $plugin_id]); + $section_storage->getSection($delta)->appendComponent($component); + $form_state->setTemporaryValue('layout_builder__component', $component); + } + return $this->doBuildForm($form, $form_state, $section_storage, $delta, $component); + } + +}