Updated to Drupal 8.6.4, which is PHP 7.3 friendly. Also updated HTMLaw library....
[yaffs-website] / web / core / modules / layout_builder / src / Form / AddBlockForm.php
1 <?php
2
3 namespace Drupal\layout_builder\Form;
4
5 use Drupal\Core\Form\FormStateInterface;
6 use Drupal\layout_builder\SectionComponent;
7 use Drupal\layout_builder\SectionStorageInterface;
8
9 /**
10  * Provides a form to add a block.
11  *
12  * @internal
13  */
14 class AddBlockForm extends ConfigureBlockFormBase {
15
16   /**
17    * {@inheritdoc}
18    */
19   public function getFormId() {
20     return 'layout_builder_add_block';
21   }
22
23   /**
24    * {@inheritdoc}
25    */
26   protected function submitLabel() {
27     return $this->t('Add Block');
28   }
29
30   /**
31    * Builds the form for the block.
32    *
33    * @param array $form
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.
39    * @param int $delta
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.
45    *
46    * @return array
47    *   The form array.
48    */
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);
55     }
56     return $this->doBuildForm($form, $form_state, $section_storage, $delta, $component);
57   }
58
59 }