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

Issue #3193006: ensure that we are not checking blank ids

parent 36b998a0
No related branches found
No related tags found
No related merge requests found
...@@ -95,19 +95,22 @@ class LayoutBuilderIdsConfigureBlock implements EventSubscriberInterface { ...@@ -95,19 +95,22 @@ class LayoutBuilderIdsConfigureBlock implements EventSubscriberInterface {
$form_state->getValue(['settings', 'layout_builder_id']) $form_state->getValue(['settings', 'layout_builder_id'])
); );
// Check if we have a duplicate id somewhere. // Ensure that we have an actual id to check.
$found_id = $this->layoutBuilderIdsService->layoutBuilderIdsCheckIds( if ($layout_builder_id !== '' && $layout_builder_id !== NULL) {
$layout_builder_id,
$form_state, // Check if we have a duplicate id somewhere.
'block' $found_id = $this->layoutBuilderIdsService->layoutBuilderIdsCheckIds(
); $layout_builder_id,
$form_state,
// If we have a duplicate id, then set the form error. 'block'
if ($found_id) { );
// Set the form error on the layout builder id element. // If we have a duplicate id, then set the form error.
$form_state->setError($form['settings']['layout_builder_id'], 'There is already a block or section with the ID "' . $layout_builder_id . '".'); 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 . '".');
}
} }
} }
......
...@@ -90,27 +90,30 @@ class LayoutBuilderIdsConfigureSection implements EventSubscriberInterface { ...@@ -90,27 +90,30 @@ class LayoutBuilderIdsConfigureSection implements EventSubscriberInterface {
*/ */
public function layoutBuilderIdsConfigureSectionFormValidation(array &$form, FormStateInterface $form_state) { public function layoutBuilderIdsConfigureSectionFormValidation(array &$form, FormStateInterface $form_state) {
// Get the layout builder id from the form, // Get the layout builder id from the form.
// also put the id through the HTML getId to make sure $layout_builder_id = $form_state->getValue(
// that we form a valid id. [
$layout_builder_id = Html::getId( 'layout_settings',
$form_state->getValue( 'layout_builder_id',
[ ]
'layout_settings',
'layout_builder_id',
],
NULL
)
); );
// Check if we have a duplicate id somewhere. // Ensure that we are not checking for blank layout builder id.
$found_id = $this->layoutBuilderIdsService->layoutBuilderIdsCheckIds($layout_builder_id, $form_state, 'section'); 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 we have a duplicate id, then set the form error.
if ($found_id) { if ($found_id) {
// Set the form error on the layout builder id form element. // 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 . '".'); $form_state->setError($form['layout_settings']['layout_builder_id'], 'There is already a block or section with the ID "' . $layout_builder_id . '".');
}
} }
} }
......
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