reverted: --- b/core/modules/block/tests/src/Functional/BlockTest.php +++ a/core/modules/block/tests/src/Functional/BlockTest.php @@ -244,11 +244,6 @@ $xpath = $this->assertSession()->buildXPathQuery('//div[@id=:id]/*', [':id' => 'block-' . str_replace('_', '-', strtolower($block['id']))]); $this->assertSession()->elementNotExists('xpath', $xpath); - // Test error when not including forward slash. - $this->drupalGet('admin/structure/block/manage/' . $block['id']); - $this->submitForm(['visibility[request_path][pages]' => 'user/login'], 'Save block'); - $this->assertSession()->pageTextContains('Paths require 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'); reverted: --- b/core/modules/system/src/Plugin/Condition/RequestPath.php +++ a/core/modules/system/src/Plugin/Condition/RequestPath.php @@ -112,22 +112,6 @@ return parent::buildConfigurationForm($form, $form_state); } - /** - * {@inheritdoc} - */ - public function validateConfigurationForm(array &$form, FormStateInterface $form_state) { - $paths = explode("\r\n", $form_state->getValue('pages')); - foreach ($paths as $path) { - if (empty($path) || $path === '' || strpos($path, '/') === 0) { - continue; - } - else { - $form_state->setErrorByName('pages', $this->t('Paths require a leading forward slash when used with the Pages setting.')); - return; - } - } - } - /** * {@inheritdoc} */ only in patch2: unchanged: --- a/core/modules/block/src/Controller/BlockLibraryController.php +++ b/core/modules/block/src/Controller/BlockLibraryController.php @@ -104,6 +104,14 @@ public function listBlocks(Request $request, $theme) { $region = $request->query->get('region'); $weight = $request->query->get('weight'); + // Adds to the "Add custom block" action url route parameters, to provide + // correct region setting after creation. + $add_action_url = $build['local_actions']['block_content_add_action']['#link']['url'] ?? NULL; + if ($add_action_url instanceof Url) { + $add_action_url->setRouteParameter('region', $region); + $build['local_actions']['block_content_add_action']['#link']['url'] = $add_action_url; + } + // Only add blocks which work without any available context. $definitions = $this->blockManager->getFilteredDefinitions('block_ui', $this->contextRepository->getAvailableContexts(), [ 'theme' => $theme, only in patch2: unchanged: --- a/core/modules/block_content/src/BlockContentForm.php +++ b/core/modules/block_content/src/BlockContentForm.php @@ -73,6 +73,7 @@ public function save(array $form, FormStateInterface $form_state) { [ 'plugin_id' => 'block_content:' . $block->uuid(), 'theme' => $theme, + 'region' => $this->getRequest()->query->get('region'), ] ); } only in patch2: unchanged: --- a/core/modules/block_content/src/Plugin/Menu/LocalAction/BlockContentAddLocalAction.php +++ b/core/modules/block_content/src/Plugin/Menu/LocalAction/BlockContentAddLocalAction.php @@ -20,6 +20,12 @@ public function getOptions(RouteMatchInterface $route_match) { if ($theme = $route_match->getParameter('theme')) { $options['query']['theme'] = $theme; } + + // If the current request has a region query parameter. + if ($region = \Drupal::request()->query->get('region')) { + $options['query']['region'] = $region; + } + // Adds a destination on custom block listing. if ($route_match->getRouteName() == 'entity.block_content.collection') { $options['query']['destination'] = Url::fromRoute('')->toString(); only in patch2: unchanged: --- a/core/modules/block_content/tests/src/Functional/BlockContentListTest.php +++ b/core/modules/block_content/tests/src/Functional/BlockContentListTest.php @@ -120,4 +120,23 @@ public function testListing() { $this->assertSession()->pageTextNotContains('Non-reusable block'); } + /** + * Tests that region value is retained when we create new block. + */ + public function testBlockRegionPlacement() { + $this->drupalLogin($this->drupalCreateUser([ + 'administer blocks', + 'translate configuration', + ])); + $this->drupalGet("admin/structure/block/library/stark", ['query' => ['region' => 'help']]); + + $this->clickLink('Add custom block'); + $this->assertSession()->statusCodeEquals(200); + $edit = [ + 'info[0][value]' => $this->randomString(), + ]; + $this->submitForm($edit, 'Save'); + $this->assertSession()->fieldValueEquals('region', 'help'); + } + }