From d039e843188ecbb222043d244a372a06b2812276 Mon Sep 17 00:00:00 2001 From: ebremner <ebremner@uwaterloo.ca> Date: Fri, 15 Jan 2021 11:25:27 -0500 Subject: [PATCH] Issue #3193006: ensure that we are not checking blank ids --- .../LayoutBuilderIdsConfigureBlock.php | 25 +++++++------ .../LayoutBuilderIdsConfigureSection.php | 37 ++++++++++--------- 2 files changed, 34 insertions(+), 28 deletions(-) diff --git a/src/EventSubscriber/LayoutBuilderIdsConfigureBlock.php b/src/EventSubscriber/LayoutBuilderIdsConfigureBlock.php index 66ff098..ffbb7f2 100644 --- a/src/EventSubscriber/LayoutBuilderIdsConfigureBlock.php +++ b/src/EventSubscriber/LayoutBuilderIdsConfigureBlock.php @@ -95,19 +95,22 @@ class LayoutBuilderIdsConfigureBlock implements EventSubscriberInterface { $form_state->getValue(['settings', 'layout_builder_id']) ); - // Check if we have a duplicate id somewhere. - $found_id = $this->layoutBuilderIdsService->layoutBuilderIdsCheckIds( - $layout_builder_id, - $form_state, - 'block' - ); - - // If we have a duplicate id, then set the form error. - if ($found_id) { + // Ensure that we have an actual id to check. + if ($layout_builder_id !== '' && $layout_builder_id !== NULL) { + + // Check if we have a duplicate id somewhere. + $found_id = $this->layoutBuilderIdsService->layoutBuilderIdsCheckIds( + $layout_builder_id, + $form_state, + 'block' + ); - // Set the form error on the layout builder id element. - $form_state->setError($form['settings']['layout_builder_id'], 'There is already a block or section with the ID "' . $layout_builder_id . '".'); + // If we have a duplicate id, then set the form error. + if ($found_id) { + // Set the form error on the layout builder id element. + $form_state->setError($form['settings']['layout_builder_id'], 'There is already a block or section with the ID "' . $layout_builder_id . '".'); + } } } diff --git a/src/EventSubscriber/LayoutBuilderIdsConfigureSection.php b/src/EventSubscriber/LayoutBuilderIdsConfigureSection.php index a4f9415..4fc53cc 100644 --- a/src/EventSubscriber/LayoutBuilderIdsConfigureSection.php +++ b/src/EventSubscriber/LayoutBuilderIdsConfigureSection.php @@ -90,27 +90,30 @@ class LayoutBuilderIdsConfigureSection implements EventSubscriberInterface { */ public function layoutBuilderIdsConfigureSectionFormValidation(array &$form, FormStateInterface $form_state) { - // Get the layout builder id from the form, - // also put the id through the HTML getId to make sure - // that we form a valid id. - $layout_builder_id = Html::getId( - $form_state->getValue( - [ - 'layout_settings', - 'layout_builder_id', - ], - NULL - ) + // Get the layout builder id from the form. + $layout_builder_id = $form_state->getValue( + [ + 'layout_settings', + 'layout_builder_id', + ] ); - // Check if we have a duplicate id somewhere. - $found_id = $this->layoutBuilderIdsService->layoutBuilderIdsCheckIds($layout_builder_id, $form_state, 'section'); + // Ensure that we are not checking for blank layout builder id. + if ($layout_builder_id !== '') { + + // Put the id through the HTML getId to make sure + // that we form a valid id. + $layout_builder_id = Html::getId($layout_builder_id); + + // Check if we have a duplicate id somewhere. + $found_id = $this->layoutBuilderIdsService->layoutBuilderIdsCheckIds($layout_builder_id, $form_state, 'section'); - // If we have a duplicate id, then set the form error. - if ($found_id) { + // If we have a duplicate id, then set the form error. + if ($found_id) { - // Set the form error on the layout builder id form element. - $form_state->setError($form['layout_settings']['layout_builder_id'], 'There is already a block or section with the ID "' . $layout_builder_id . '".'); + // Set the form error on the layout builder id form element. + $form_state->setError($form['layout_settings']['layout_builder_id'], 'There is already a block or section with the ID "' . $layout_builder_id . '".'); + } } } -- GitLab