diff --git a/core/modules/block/tests/src/Functional/BlockTest.php b/core/modules/block/tests/src/Functional/BlockTest.php index 2e16a24d618f831ecf32a17f8464927e0b0c6c62..e68f58bc4413d095c23cf3c141bd5746db20b687 100644 --- a/core/modules/block/tests/src/Functional/BlockTest.php +++ b/core/modules/block/tests/src/Functional/BlockTest.php @@ -244,6 +244,17 @@ public function testBlock() { $xpath = $this->assertSession()->buildXPathQuery('//div[@id=:id]/*', [':id' => 'block-' . str_replace('_', '-', strtolower($block['id']))]); $this->assertSession()->elementNotExists('xpath', $xpath); + $pages = [ + '', + '<front>', + '/valid-page', + 'user/login', + ]; + // Test error when not including forward slash. + $this->drupalGet('admin/structure/block/manage/' . $block['id']); + $this->submitForm(['visibility[request_path][pages]' => implode("\n", $pages)], 'Save block'); + $this->assertSession()->pageTextContains('The path user/login requires a leading forward slash when used with the Pages setting.'); + // Test deleting the block from the edit form. $this->drupalGet('admin/structure/block/manage/' . $block['id']); $this->clickLink('Remove block'); diff --git a/core/modules/system/src/Plugin/Condition/RequestPath.php b/core/modules/system/src/Plugin/Condition/RequestPath.php index 796277986b8cbbb18da7c8db77cdb44a1daa87cd..9b4bd474d1a7888aa27adb92ffa6c98dd91edc74 100644 --- a/core/modules/system/src/Plugin/Condition/RequestPath.php +++ b/core/modules/system/src/Plugin/Condition/RequestPath.php @@ -112,6 +112,19 @@ public function buildConfigurationForm(array $form, FormStateInterface $form_sta return parent::buildConfigurationForm($form, $form_state); } + /** + * {@inheritdoc} + */ + public function validateConfigurationForm(array &$form, FormStateInterface $form_state) { + $paths = array_map('trim', explode("\n", $form_state->getValue('pages'))); + foreach ($paths as $path) { + if (empty($path) || $path === '<front>' || str_starts_with($path, '/')) { + continue; + } + $form_state->setErrorByName('pages', $this->t("The path %path requires a leading forward slash when used with the Pages setting.", ['%path' => $path])); + } + } + /** * {@inheritdoc} */