From ef506a338bfbdd2fb066e2ade474d7d8aebfe6e0 Mon Sep 17 00:00:00 2001 From: ebremner <ebremner@uwaterloo.ca> Date: Tue, 5 May 2020 14:26:06 -0400 Subject: [PATCH] Coding standards --- layout_builder_ids.services.yml | 2 +- .../LayoutBuilderIdsConfigureBlock.php | 20 ++++--------------- .../LayoutBuilderIdsConfigureSection.php | 10 ++-------- 3 files changed, 7 insertions(+), 25 deletions(-) diff --git a/layout_builder_ids.services.yml b/layout_builder_ids.services.yml index b0ed7ed..ace75ec 100644 --- a/layout_builder_ids.services.yml +++ b/layout_builder_ids.services.yml @@ -1,6 +1,6 @@ services: layout_builder_ids.render_block_component_subscriber: - class: Drupal\layout_builder_ids\EventSubscriber\LayoutBuilderIdsRenderSubscriber + class: 'Drupal\layout_builder_ids\EventSubscriber\LayoutBuilderIdsRenderSubscriber' tags: - { name: event_subscriber } layout_builder_ids.configure_section_form: diff --git a/src/EventSubscriber/LayoutBuilderIdsConfigureBlock.php b/src/EventSubscriber/LayoutBuilderIdsConfigureBlock.php index 607fc75..1c50164 100644 --- a/src/EventSubscriber/LayoutBuilderIdsConfigureBlock.php +++ b/src/EventSubscriber/LayoutBuilderIdsConfigureBlock.php @@ -25,26 +25,17 @@ class LayoutBuilderIdsConfigureBlock implements EventSubscriberInterface { $form = &$event->getForm(); // 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') { - - // 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(); + 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 = $component->get('layout_builder_id'); + $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' => 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.'), ]; @@ -64,11 +55,8 @@ class LayoutBuilderIdsConfigureBlock implements EventSubscriberInterface { // If there is in id, save it in config. if ($layout_builder_id !== NULL) { - // Load in the form object. - $formObject = $form_state->getFormObject(); - // Load in the component/block. - $component = $formObject->getCurrentComponent(); + $component = $form_state->getFormObject()->getCurrentComponent(); // Set the layout_builder_id. $component->set('layout_builder_id', Html::getId($layout_builder_id)); diff --git a/src/EventSubscriber/LayoutBuilderIdsConfigureSection.php b/src/EventSubscriber/LayoutBuilderIdsConfigureSection.php index 64ddace..41a9ced 100644 --- a/src/EventSubscriber/LayoutBuilderIdsConfigureSection.php +++ b/src/EventSubscriber/LayoutBuilderIdsConfigureSection.php @@ -29,21 +29,15 @@ class LayoutBuilderIdsConfigureSection implements EventSubscriberInterface { // If we are on a configure section form, alter it. 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. - $config = $formObject->getLayout()->getConfiguration(); + $config = $event->getFormState()->getFormObject()->getLayout()->getConfiguration(); // Add the section id to the configure form. $form['layout_settings']['layout_builder_id'] = [ '#type' => 'textfield', '#title' => 'Section ID', '#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.'), ]; -- GitLab