public static function LayoutBuilderIdsConfigureBlock::alterForm in Layout builder ids 2.0.x
Same name and namespace in other branches
- 8 src/EventSubscriber/LayoutBuilderIdsConfigureBlock.php \Drupal\layout_builder_ids\EventSubscriber\LayoutBuilderIdsConfigureBlock::alterForm()
Alter form.
Parameters
\Drupal\core_event_dispatcher\Event\Form\FormAlterEvent $event: The event.
File
- src/
EventSubscriber/ LayoutBuilderIdsConfigureBlock.php, line 40
Class
- LayoutBuilderIdsConfigureBlock
- Add block ids to layout builder sections.
Namespace
Drupal\layout_builder_ids\EventSubscriberCode
public static function alterForm(FormAlterEvent $event) : void {
// Get the form from the event.
$form =& $event
->getForm();
// If we are on a configure section form, alter it.
if (in_array($form['#form_id'], [
'layout_builder_add_block',
'layout_builder_update_block',
], TRUE)) {
// Pull out the layout_builder_id from config.
$layout_builder_id = $event
->getFormState()
->getFormObject()
->getCurrentComponent()
->get('layout_builder_id');
// Add the section id to the configure form.
$form['settings']['layout_builder_id'] = [
'#type' => 'textfield',
'#title' => 'Block ID',
'#weight' => 99,
'#default_value' => $layout_builder_id ?: NULL,
'#description' => t('Block ID is an optional setting which is used to support an anchor link to this block. For example, entering "feature" lets you link directly to this block by adding "#feature" to the end of the URL.</br>IDs should start with a letter, may only contain letters, numbers, underscores, hyphens, and periods, and should be unique on the page.'),
];
// Add the form validation for configure block.
$form['#validate'][] = 'Drupal\\layout_builder_ids\\EventSubscriber\\LayoutBuilderIdsConfigureBlock::layoutBuilderIdsConfigureBlockFormValidation';
// Add our custom submit function.
array_unshift($form['#submit'], 'Drupal\\layout_builder_ids\\EventSubscriber\\LayoutBuilderIdsConfigureBlock::layoutBuilderIdsConfigureBlockSubmitForm');
}
}