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. + // Adds route parameters for "Add custom block" action uri + // Provides correct region setting on block 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 @@ -5,6 +5,7 @@ use Drupal\Core\Menu\LocalActionDefault; use Drupal\Core\Routing\RouteMatchInterface; use Drupal\Core\Url; +use Symfony\Component\HttpFoundation\RequestStack; /** * Modifies the 'Add custom block' local action. @@ -13,4 +14,27 @@ /** + * Request stack. + * + * @var \Symfony\Component\HttpFoundation\RequestStack + */ + protected $requestmatch; + + /** + * Constructor function. + */ + public function __construct(RequestStack $request) { + $this->requestMatch = $request; + } + + /** + * Creates container. + */ + public static function create(ContainerInterface $container) { + return new static( + $container->get('request_stack') + ); + } + + /** * {@inheritdoc} */ @@ -22,7 +46,7 @@ } // If the current request has a region query parameter. - if ($region = \Drupal::request()->query->get('region')) { + if ($region = $this->requestMatch->query->get('region')) { $options['query']['region'] = $region; }