class AddBlockForm
Same name and namespace in other branches
- 11.x core/modules/layout_builder/src/Form/AddBlockForm.php \Drupal\layout_builder\Form\AddBlockForm
- 10 core/modules/layout_builder/src/Form/AddBlockForm.php \Drupal\layout_builder\Form\AddBlockForm
- 9 core/modules/layout_builder/src/Form/AddBlockForm.php \Drupal\layout_builder\Form\AddBlockForm
- 8.9.x core/modules/layout_builder/src/Form/AddBlockForm.php \Drupal\layout_builder\Form\AddBlockForm
Provides a form to add a block.
@internal Form classes are internal.
Hierarchy
- class \Drupal\Core\Form\FormBase implements \Drupal\Core\Form\FormInterface, \Drupal\Core\DependencyInjection\ContainerInjectionInterface uses \Drupal\Core\DependencyInjection\DependencySerializationTrait, \Drupal\Core\Htmx\HtmxRequestInfoTrait, \Drupal\Core\Logger\LoggerChannelTrait, \Drupal\Core\Messenger\MessengerTrait, \Drupal\Core\Routing\RedirectDestinationTrait, \Drupal\Core\StringTranslation\StringTranslationTrait
- class \Drupal\layout_builder\Form\ConfigureBlockFormBase implements \Drupal\Core\Form\BaseFormIdInterface, \Drupal\Core\Form\WorkspaceDynamicSafeFormInterface uses \Drupal\Core\Ajax\AjaxFormHelperTrait, \Drupal\Core\Plugin\ContextAwarePluginAssignmentTrait, \Drupal\layout_builder\Context\LayoutBuilderContextTrait, \Drupal\layout_builder\Controller\LayoutRebuildTrait, \Drupal\layout_builder\Form\WorkspaceSafeFormTrait extends \Drupal\Core\Form\FormBase
- class \Drupal\layout_builder\Form\AddBlockForm uses \Drupal\layout_builder\LayoutBuilderHighlightTrait extends \Drupal\layout_builder\Form\ConfigureBlockFormBase
- class \Drupal\layout_builder\Form\ConfigureBlockFormBase implements \Drupal\Core\Form\BaseFormIdInterface, \Drupal\Core\Form\WorkspaceDynamicSafeFormInterface uses \Drupal\Core\Ajax\AjaxFormHelperTrait, \Drupal\Core\Plugin\ContextAwarePluginAssignmentTrait, \Drupal\layout_builder\Context\LayoutBuilderContextTrait, \Drupal\layout_builder\Controller\LayoutRebuildTrait, \Drupal\layout_builder\Form\WorkspaceSafeFormTrait extends \Drupal\Core\Form\FormBase
Expanded class hierarchy of AddBlockForm
1 string reference to 'AddBlockForm'
- layout_builder.routing.yml in core/
modules/ layout_builder/ layout_builder.routing.yml - core/modules/layout_builder/layout_builder.routing.yml
File
-
core/
modules/ layout_builder/ src/ Form/ AddBlockForm.php, line 16
Namespace
Drupal\layout_builder\FormView source
class AddBlockForm extends ConfigureBlockFormBase {
use LayoutBuilderHighlightTrait;
/**
* {@inheritdoc}
*/
public function getFormId() {
return 'layout_builder_add_block';
}
/**
* {@inheritdoc}
*/
protected function submitLabel() {
return $this->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->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);
}
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.