diff --git a/core/modules/block/block.module b/core/modules/block/block.module index 6f341ad..1ed1a6f 100644 --- a/core/modules/block/block.module +++ b/core/modules/block/block.module @@ -7,6 +7,7 @@ use Drupal\block\BlockInterface; use Drupal\Component\Plugin\Exception\PluginException; +use Drupal\Tests\Core\Routing\RoutingRequestContext; use Symfony\Cmf\Component\Routing\RouteObjectInterface; /** @@ -119,7 +120,7 @@ function block_page_build(&$page) { // Fetch a list of regions for the current theme. $all_regions = system_region_list($theme); - if (\Drupal::request()->attributes->get(RouteObjectInterface::ROUTE_NAME) != 'block.admin_demo') { + if (RoutingRequestContext::get(\Drupal::request())->getRouteName() != 'block.admin_demo') { // Load all region content assigned via blocks. foreach (array_keys($all_regions) as $region) { // Assign blocks to region. diff --git a/core/modules/block/custom_block/lib/Drupal/custom_block/Plugin/Menu/LocalAction/CustomBlockAddLocalAction.php b/core/modules/block/custom_block/lib/Drupal/custom_block/Plugin/Menu/LocalAction/CustomBlockAddLocalAction.php index af9b359..47af68c 100644 --- a/core/modules/block/custom_block/lib/Drupal/custom_block/Plugin/Menu/LocalAction/CustomBlockAddLocalAction.php +++ b/core/modules/block/custom_block/lib/Drupal/custom_block/Plugin/Menu/LocalAction/CustomBlockAddLocalAction.php @@ -8,6 +8,7 @@ namespace Drupal\custom_block\Plugin\Menu\LocalAction; use Drupal\Core\Menu\LocalActionDefault; +use Drupal\Tests\Core\Routing\RoutingRequestContext; use Symfony\Cmf\Component\Routing\RouteObjectInterface; use Symfony\Component\HttpFoundation\Request; @@ -26,11 +27,11 @@ public function getOptions(Request $request) { $options['query']['theme'] = $request->attributes->get('theme'); } // Adds a destination on custom block listing. - if ($request->attributes->get(RouteObjectInterface::ROUTE_NAME) == 'custom_block.list') { + if (RoutingRequestContext::get($request)->getRouteName() == 'custom_block.list') { $options['query']['destination'] = 'admin/structure/block/custom-blocks'; } // Adds a destination on custom block listing. - if ($request->attributes->get(RouteObjectInterface::ROUTE_NAME) == 'custom_block.list') { + if (RoutingRequestContext::get($request)->getRouteName() == 'custom_block.list') { $options['query']['destination'] = 'admin/structure/block/custom-blocks'; } return $options; diff --git a/core/modules/block/lib/Drupal/block/Theme/AdminDemoNegotiator.php b/core/modules/block/lib/Drupal/block/Theme/AdminDemoNegotiator.php index d175b91..591aa8b 100644 --- a/core/modules/block/lib/Drupal/block/Theme/AdminDemoNegotiator.php +++ b/core/modules/block/lib/Drupal/block/Theme/AdminDemoNegotiator.php @@ -8,6 +8,7 @@ namespace Drupal\block\Theme; use Drupal\Core\Theme\ThemeNegotiatorInterface; +use Drupal\Tests\Core\Routing\RoutingRequestContext; use Symfony\Cmf\Component\Routing\RouteObjectInterface; use Symfony\Component\HttpFoundation\Request; @@ -20,7 +21,7 @@ class AdminDemoNegotiator implements ThemeNegotiatorInterface { * {@inheritdoc} */ public function applies(Request $request) { - return $request->attributes->get(RouteObjectInterface::ROUTE_NAME) == 'block.admin_demo'; + return RoutingRequestContext::get($request)->getRouteName() == 'block.admin_demo'; } /** diff --git a/core/modules/config_translation/lib/Drupal/config_translation/Controller/ConfigTranslationController.php b/core/modules/config_translation/lib/Drupal/config_translation/Controller/ConfigTranslationController.php index 0235678..642da9f 100644 --- a/core/modules/config_translation/lib/Drupal/config_translation/Controller/ConfigTranslationController.php +++ b/core/modules/config_translation/lib/Drupal/config_translation/Controller/ConfigTranslationController.php @@ -15,6 +15,7 @@ use Drupal\Core\ParamConverter\ParamNotConvertedException; use Drupal\Core\PathProcessor\InboundPathProcessorInterface; use Drupal\Core\Session\AccountInterface; +use Drupal\Tests\Core\Routing\RoutingRequestContext; use Symfony\Cmf\Component\Routing\RouteObjectInterface; use Symfony\Component\DependencyInjection\ContainerInterface; use Symfony\Component\HttpFoundation\Request; @@ -170,7 +171,7 @@ public function itemPage(Request $request, $plugin_id) { $route_request = $this->getRequestForPath($request, $mapper->getBasePath()); $edit_access = FALSE; if (!empty($route_request)) { - $route_name = $route_request->attributes->get(RouteObjectInterface::ROUTE_NAME); + $route_name = RoutingRequestContext::get($route_request)->getRouteName(); // Note that the parameters don't really matter here since we're // passing in the request which already has the upcast attributes. $parameters = array(); diff --git a/core/tests/Drupal/Tests/Core/Routing/RoutingRequestContext.php b/core/tests/Drupal/Tests/Core/Routing/RoutingRequestContext.php new file mode 100644 index 0000000..9f97e8c --- /dev/null +++ b/core/tests/Drupal/Tests/Core/Routing/RoutingRequestContext.php @@ -0,0 +1,93 @@ +request = $request; + } + + public static function get(Request $request) { + return new RoutingRequestContext($request); + } + + + + /** + * Get the route name. + * + * @return string + */ + public function getRouteName() { + return $this->request->attributes->get(RouteObjectInterface::ROUTE_NAME); + } + + /** + * Get the route object. + * + * @return \Symfony\Component\Routing\Route + */ + public function getRouteObject() { + return $this->request->attributes->get(RouteObjectInterface::ROUTE_OBJECT); + } + + /** + * Gets the internal path. + * + * @return string + * The internal requested path without path aliases. + */ + public function getSystemPath() { + return $this->request->attributes->get('_system_path'); + } + + /** + * Gets the raw variables. + * + * @return \Symfony\Component\HttpFoundation\ParameterBag + * The original variables prior to conversion by the ParamConverterManager. + */ + public function getRawVariables() { + return $this->request->attributes->get('_raw_variables'); + } + + /** + * Gets a parameter value. + * + * @param string $name + * A parameter name. + * + * @return mixed + * The parameter value + */ + public function getParameter($name) { + return $this->request->attributes->get($name); + } + +} + diff --git a/core/vendor/symfony/http-kernel/Symfony/Component/HttpKernel/EventListener/RouterListener.php b/core/vendor/symfony/http-kernel/Symfony/Component/HttpKernel/EventListener/RouterListener.php index 27ac632..deba8c0 100644 --- a/core/vendor/symfony/http-kernel/Symfony/Component/HttpKernel/EventListener/RouterListener.php +++ b/core/vendor/symfony/http-kernel/Symfony/Component/HttpKernel/EventListener/RouterListener.php @@ -63,7 +63,7 @@ public function __construct($matcher, RequestContext $context = null, LoggerInte } if (null === $context && !$matcher instanceof RequestContextAwareInterface) { - throw new \InvalidArgumentException('You must either pass a RequestContext or the matcher must implement RequestContextAwareInterface.'); + throw new \InvalidArgumentException('You must either pass a RoutingRequestContext or the matcher must implement RequestContextAwareInterface.'); } $this->matcher = $matcher; diff --git a/core/vendor/symfony/routing/Symfony/Component/Routing/Generator/Dumper/PhpGeneratorDumper.php b/core/vendor/symfony/routing/Symfony/Component/Routing/Generator/Dumper/PhpGeneratorDumper.php index 4d19d2a..cfa5528 100644 --- a/core/vendor/symfony/routing/Symfony/Component/Routing/Generator/Dumper/PhpGeneratorDumper.php +++ b/core/vendor/symfony/routing/Symfony/Component/Routing/Generator/Dumper/PhpGeneratorDumper.php @@ -62,7 +62,7 @@ class {$options['class']} extends {$options['base_class']} /** * Constructor. */ - public function __construct(RequestContext \$context, LoggerInterface \$logger = null) + public function __construct(RoutingRequestContext \$context, LoggerInterface \$logger = null) { \$this->context = \$context; \$this->logger = \$logger; diff --git a/core/vendor/symfony/routing/Symfony/Component/Routing/Matcher/Dumper/PhpMatcherDumper.php b/core/vendor/symfony/routing/Symfony/Component/Routing/Matcher/Dumper/PhpMatcherDumper.php index 784f309..e64ecc8 100644 --- a/core/vendor/symfony/routing/Symfony/Component/Routing/Matcher/Dumper/PhpMatcherDumper.php +++ b/core/vendor/symfony/routing/Symfony/Component/Routing/Matcher/Dumper/PhpMatcherDumper.php @@ -67,7 +67,7 @@ class {$options['class']} extends {$options['base_class']} /** * Constructor. */ - public function __construct(RequestContext \$context) + public function __construct(RoutingRequestContext \$context) { \$this->context = \$context; }