diff -u b/core/modules/block/src/Controller/BlockLibraryController.php b/core/modules/block/src/Controller/BlockLibraryController.php --- b/core/modules/block/src/Controller/BlockLibraryController.php +++ b/core/modules/block/src/Controller/BlockLibraryController.php @@ -104,8 +104,8 @@ $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 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); diff -u b/core/modules/block_content/src/Plugin/Menu/LocalAction/BlockContentAddLocalAction.php b/core/modules/block_content/src/Plugin/Menu/LocalAction/BlockContentAddLocalAction.php --- b/core/modules/block_content/src/Plugin/Menu/LocalAction/BlockContentAddLocalAction.php +++ b/core/modules/block_content/src/Plugin/Menu/LocalAction/BlockContentAddLocalAction.php @@ -22,7 +22,7 @@ } // If the current request has a region query parameter. - if ($region = \Drupal::request()->query->get('region')) { + if ($region = $this->request->query->get('region')) { $options['query']['region'] = $region; } diff -u b/core/modules/block_content/tests/src/Functional/BlockContentListTest.php b/core/modules/block_content/tests/src/Functional/BlockContentListTest.php --- b/core/modules/block_content/tests/src/Functional/BlockContentListTest.php +++ b/core/modules/block_content/tests/src/Functional/BlockContentListTest.php @@ -71,4 +71,23 @@ /** + * 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'); + } + + /** * Tests the custom block listing page with different permissions. */ @@ -120,23 +139,4 @@ $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'); } } only in patch2: unchanged: --- a/core/lib/Drupal/Core/Menu/LocalActionDefault.php +++ b/core/lib/Drupal/Core/Menu/LocalActionDefault.php @@ -26,6 +26,13 @@ class LocalActionDefault extends PluginBase implements LocalActionInterface, Con */ protected $routeProvider; + /** + * The current request. + * + * @var \Symfony\Component\HttpFoundation\Request + */ + protected $request; + /** * Constructs a LocalActionDefault object. * @@ -37,11 +44,14 @@ class LocalActionDefault extends PluginBase implements LocalActionInterface, Con * The plugin implementation definition. * @param \Drupal\Core\Routing\RouteProviderInterface $route_provider * The route provider to load routes by name. + * @param \Symfony\Component\HttpFoundation\Request $request + * The current request. */ - public function __construct(array $configuration, $plugin_id, $plugin_definition, RouteProviderInterface $route_provider) { + public function __construct(array $configuration, $plugin_id, $plugin_definition, RouteProviderInterface $route_provider, Request $request) { parent::__construct($configuration, $plugin_id, $plugin_definition); $this->routeProvider = $route_provider; + $this->request = $request; } /** @@ -52,7 +62,8 @@ public static function create(ContainerInterface $container, array $configuratio $configuration, $plugin_id, $plugin_definition, - $container->get('router.route_provider') + $container->get('router.route_provider'), + $container->get('request_stack')->getCurrentRequest(), ); }