AddBlockForm.php in Drupal 9
File
core/modules/layout_builder/src/Form/AddBlockForm.php
View source
<?php
namespace Drupal\layout_builder\Form;
use Drupal\Core\Form\FormStateInterface;
use Drupal\layout_builder\LayoutBuilderHighlightTrait;
use Drupal\layout_builder\SectionComponent;
use Drupal\layout_builder\SectionStorageInterface;
class AddBlockForm extends ConfigureBlockFormBase {
use LayoutBuilderHighlightTrait;
public function getFormId() {
return 'layout_builder_add_block';
}
protected function submitLabel() {
return $this
->t('Add block');
}
public function buildForm(array $form, FormStateInterface $form_state, SectionStorageInterface $section_storage = NULL, $delta = NULL, $region = NULL, $plugin_id = NULL) {
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);
}
}