Skip to content
Snippets Groups Projects
Commit ef506a33 authored by Eric Bremner's avatar Eric Bremner
Browse files

Coding standards

parent 9bcf40f7
No related branches found
No related tags found
No related merge requests found
services: services:
layout_builder_ids.render_block_component_subscriber: layout_builder_ids.render_block_component_subscriber:
class: Drupal\layout_builder_ids\EventSubscriber\LayoutBuilderIdsRenderSubscriber class: 'Drupal\layout_builder_ids\EventSubscriber\LayoutBuilderIdsRenderSubscriber'
tags: tags:
- { name: event_subscriber } - { name: event_subscriber }
layout_builder_ids.configure_section_form: layout_builder_ids.configure_section_form:
......
...@@ -25,26 +25,17 @@ class LayoutBuilderIdsConfigureBlock implements EventSubscriberInterface { ...@@ -25,26 +25,17 @@ class LayoutBuilderIdsConfigureBlock implements EventSubscriberInterface {
$form = &$event->getForm(); $form = &$event->getForm();
// If we are on a configure section form, alter it. // If we are on a configure section form, alter it.
if ($form['#form_id'] == 'layout_builder_add_block' || $form['#form_id'] == 'layout_builder_update_block') { if (in_array($form['#form_id'], ['layout_builder_add_block', 'layout_builder_update_block'], TRUE)) {
// Get the form state.
$form_state = &$event->getFormState();
// Load in the form object.
$formObject = $form_state->getFormObject();
// Load in the component/block.
$component = $formObject->getCurrentComponent();
// Pull out the layout_builder_id from config. // Pull out the layout_builder_id from config.
$layout_builder_id = $component->get('layout_builder_id'); $layout_builder_id = &$event->getFormState()->getFormObject()->getCurrentComponent()->get('layout_builder_id');
// Add the section id to the configure form. // Add the section id to the configure form.
$form['settings']['layout_builder_id'] = [ $form['settings']['layout_builder_id'] = [
'#type' => 'textfield', '#type' => 'textfield',
'#title' => 'Block ID', '#title' => 'Block ID',
'#weight' => 0, '#weight' => 0,
'#default_value' => $layout_builder_id ? $layout_builder_id : NULL, '#default_value' => $layout_builder_id ?: NULL,
'#description' => t('Enter an ID for the block. IDs can contain letters, numbers, underscore, hyphen and period characters, and should start with a letter.'), '#description' => t('Enter an ID for the block. IDs can contain letters, numbers, underscore, hyphen and period characters, and should start with a letter.'),
]; ];
...@@ -64,11 +55,8 @@ class LayoutBuilderIdsConfigureBlock implements EventSubscriberInterface { ...@@ -64,11 +55,8 @@ class LayoutBuilderIdsConfigureBlock implements EventSubscriberInterface {
// If there is in id, save it in config. // If there is in id, save it in config.
if ($layout_builder_id !== NULL) { if ($layout_builder_id !== NULL) {
// Load in the form object.
$formObject = $form_state->getFormObject();
// Load in the component/block. // Load in the component/block.
$component = $formObject->getCurrentComponent(); $component = $form_state->getFormObject()->getCurrentComponent();
// Set the layout_builder_id. // Set the layout_builder_id.
$component->set('layout_builder_id', Html::getId($layout_builder_id)); $component->set('layout_builder_id', Html::getId($layout_builder_id));
......
...@@ -29,21 +29,15 @@ class LayoutBuilderIdsConfigureSection implements EventSubscriberInterface { ...@@ -29,21 +29,15 @@ class LayoutBuilderIdsConfigureSection implements EventSubscriberInterface {
// If we are on a configure section form, alter it. // If we are on a configure section form, alter it.
if ($form['#form_id'] == 'layout_builder_configure_section') { if ($form['#form_id'] == 'layout_builder_configure_section') {
// Get the form state.
$form_state = $event->getFormState();
// Get the form object.
$formObject = $form_state->getFormObject();
// Get the config for the section. // Get the config for the section.
$config = $formObject->getLayout()->getConfiguration(); $config = $event->getFormState()->getFormObject()->getLayout()->getConfiguration();
// Add the section id to the configure form. // Add the section id to the configure form.
$form['layout_settings']['layout_builder_id'] = [ $form['layout_settings']['layout_builder_id'] = [
'#type' => 'textfield', '#type' => 'textfield',
'#title' => 'Section ID', '#title' => 'Section ID',
'#weight' => 0, '#weight' => 0,
'#default_value' => isset($config['layout_builder_id']) ? $config['layout_builder_id'] : '', '#default_value' => $config['layout_builder_id'] ?: NULL,
'#description' => t('Enter an ID for the section. IDs can contain letters, numbers, underscore, hyphen and period characters, and should start with a letter.'), '#description' => t('Enter an ID for the section. IDs can contain letters, numbers, underscore, hyphen and period characters, and should start with a letter.'),
]; ];
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment