Problem/Motivation

After the introduction of the route match class we can get rid of a lot of the magic attributes of the request.
Let's try to replace a lot of them

Proposed resolution

Replace usages of the request attributes with the request match.

We don't convert the calls to _system_path in this issue, there is a separate one for that already.
Left over calls to ->attributes->get(MAGIC_KEY) after this issue:

Targets
Occurrences of '->attributes->get(' in Project
core (37 usages found)
core/lib/Drupal/Core/Controller (3 usages found)
ControllerResolver.php (2 usages found)
(92: 32) if (!$controller = $request->attributes->get('_controller')) {
(141: 77) $raw_parameters = $request->attributes->has('_raw_variables') ? $request->attributes->get('_raw_variables') : [];
// Internal detail of the routing system
TitleResolver.php (1 usage found)
(60: 38) if (($raw_parameters = $request->attributes->get('_raw_variables'))) {
// Similar class as the controller resolver, just for titles
core/lib/Drupal/Core/EventSubscriber (6 usages found)
ContentControllerSubscriber.php (1 usage found)
(51: 18) if (!$request->attributes->get('_format')) {
// _format is a magic key of the request class, see Request::getRequestFormat() #2364011: [meta] External caches mix up response formats on URLs where content negotiation is in use might affect those
ContentFormControllerSubscriber.php (1 usage found)
(68: 25) if ($form = $request->attributes->get('_form')) {
// _format is the way how we deal with forms, also just a internal detail. Contrib does not have to care about it
DefaultExceptionHtmlSubscriber.php (2 usages found)
(100: 28) $system_path = $request->attributes->get('_system_path');
(112: 60) $sub_request->attributes->set('exception', $request->attributes->get('exception'));
// 'exception' is still there, you could consider it as detail, but its the "api" to get the parent exception, when you render a exception page
ExceptionLoggingSubscriber.php (2 usages found)
(50: 77) $this->logger->get('access denied')->warning(String::checkPlain($request->attributes->get('_system_path')));
(63: 78) $this->logger->get('page not found')->warning(String::checkPlain($request->attributes->get('_system_path')));
core/lib/Drupal/Core/Form (1 usage found)
FormSubmitter.php (1 usage found)
(142: 60) $url = $this->urlGenerator->generateFromPath($request->attributes->get('_system_path'), array(
core/lib/Drupal/Core/Routing (6 usages found)
RouteMatch.php (4 usages found)
(84: 17) if ($request->attributes->get(RouteObjectInterface::ROUTE_OBJECT)) {
(86: 26) if ($raw = $request->attributes->get('_raw_variables')) {
(90: 17) $request->attributes->get(RouteObjectInterface::ROUTE_NAME),
(91: 17) $request->attributes->get(RouteObjectInterface::ROUTE_OBJECT),
// the route match itself, ... somewhere needs to happen the magic :)
RouteProvider.php (1 usage found)
(116: 29) $path = '/' . $request->attributes->get('_system_path');
UrlMatcher.php (1 usage found)
(34: 29) $path = '/' . $request->attributes->get('_system_path');
core/lib/Drupal/Core/Routing/Enhancer (1 usage found)
AuthenticationEnhancer.php (1 usage found)
(58: 40) $auth_provider_triggered = $request->attributes->get('_authentication_provider');
// Internal detail (might change, see the various related issues to that)
core/modules/config_translation/src (1 usage found)
ConfigNamesMapper.php (1 usage found)
(365: 73) $this->langcode = $route_match->getParameter('langcode') ?: $request->attributes->get('langcode');
// We have a todo for that, see #2295255: Convert ConfigMapperInterface::populateFromRequest() to use RouteMatch
core/modules/rest/src/Access (1 usage found)
CSRFAccessCheck.php (1 usage found)
(57: 23) $cookie = $request->attributes->get('_authentication_provider') == 'cookie';
// Same internal detail
core/modules/system/src/Plugin/Condition (1 usage found)
RequestPath.php (1 usage found)
(146: 21) $path = $request->attributes->get('_system_path');
core/modules/system/src/Tests/HttpKernel (2 usages found)
StackKernelIntegrationTest.php (2 usages found)
(48: 32) $this->assertEqual($request->attributes->get('_hello'), 'world');
(49: 32) $this->assertEqual($request->attributes->get('_previous_optional_argument'), 'test_argument');
// Just tests ... here.
core/modules/system/tests/modules/form_test/src (1 usage found)
FormTestControllerObject.php (1 usage found)
(42: 53) $form['request_attribute']['#markup'] = $request->attributes->get('request_attribute');
core/modules/system/tests/modules/httpkernel_test/src/HttpKernel (1 usage found)
TestMiddleware.php (1 usage found)
(51: 71) $request->attributes->set('_previous_optional_argument', $request->attributes->get('_optional_argument'));
core/modules/system/tests/modules/theme_test/src/EventSubscriber (2 usages found)
ThemeTestSubscriber.php (2 usages found)
(35: 29) $current_path = $request->attributes->get('_system_path');
(60: 29) $current_path = $request->attributes->get('_system_path');
core/modules/views/src/Plugin/views/argument_default (1 usage found)
Raw.php (1 usage found)
(96: 38) $path = $this->view->getRequest()->attributes->get('_system_path')
Usage in comments (1 usage found)
d8 (1 usage found)
core/lib/Drupal/Core/Controller (1 usage found)
ControllerResolverInterface.php (1 usage found)
(24: 49) * The controller attribute like in $request->attributes->get('_controller')

Remaining tasks

User interface changes

API changes

Original report by @effulgentsia

Follow-up to #2238217: Introduce a RouteMatch class.

Beta phase evaluation

Reference: https://www.drupal.org/core/beta-changes
Issue category Task: part of the critical #2124749: [meta] Stop using $request->attributes->get(MAGIC_KEY) as a public API
Issue priority Critical, because its part of #2124749: [meta] Stop using $request->attributes->get(MAGIC_KEY) as a public API
Disruption Just internal changes inside drupal itself

Comments

catch’s picture

Status: Postponed » Active
tim.plunkett’s picture

Title: [PP-1] Convert all direct usages within module code of routing related request attributes to use RouteMatchInterface instead » Convert all direct usages within module code of routing related request attributes to use RouteMatchInterface instead
Assigned: Unassigned » tim.plunkett

Going to look at this.

tim.plunkett’s picture

I looked at breadcrumbs first, and realized it was a sizable change on its own (and an API change), so I split it out to #2292025: Convert BreadcrumbBuilderInterface applies() and build() to use RouteMatch.

tim.plunkett’s picture

Status: Active » Needs review
StatusFileSize
new36.58 KB

A bunch of remaining usages are because we don't have something like #1837388: Provide a ParamConverter than can upcast any entity..

I also opened a couple child issues.

Here is what I have so far.

Status: Needs review » Needs work

The last submitted patch, 4: attributes-2281619-4.patch, failed testing.

tim.plunkett’s picture

Status: Needs work » Needs review
StatusFileSize
new36.58 KB

"yeah, you need all the semicolons"
- @drumm

Status: Needs review » Needs work

The last submitted patch, 6: attributes-2281619-6.patch, failed testing.

tim.plunkett’s picture

Status: Needs work » Needs review
StatusFileSize
new45.82 KB
new10.92 KB

Fixed some tests.

Status: Needs review » Needs work

The last submitted patch, 8: attributes-2281619-8.patch, failed testing.

tim.plunkett’s picture

Status: Needs work » Needs review
StatusFileSize
new47.28 KB
new2.78 KB
tim.plunkett’s picture

StatusFileSize
new72.08 KB

Rerolled and added more fixes.

Status: Needs review » Needs work

The last submitted patch, 11: attributes-2281619-11.patch, failed testing.

tim.plunkett’s picture

Status: Needs work » Needs review
StatusFileSize
new53.1 KB

There are a bunch of weird problems with config_translation, I might need to split those out to a new issue. Removing for now.

xjm’s picture

Title: Convert all direct usages within module code of routing related request attributes to use RouteMatchInterface instead » Convert most direct usages within module code of routing related request attributes to use RouteMatchInterface instead
Issue tags: -beta blocker +beta target

Discussed with @tim.plunkett and @effulgentsia. We'll add @todos in this patch for the remaining issues Tim hasn't solved yet here (c_t, quickedit, maybe others) and then should be in good shape for beta with this.

tim.plunkett’s picture

Issue tags: +RouteMatch
StatusFileSize
new2.83 KB
new55.93 KB

With these changes and the child issues, we cover everything except the explicit test coverage for $request->attributes.

effulgentsia’s picture

This patch adds 9 calls to RouteMatch::createFromRequest(). I think most, if not all, of those are wrong. I think in general, we want code to keep $request and $route_match as separate concepts, not assume that the latter is always derived from the former.

Note that in HEAD, outside of tests and CurrentRouteMatch, we have only one place where "outside" code calls RouteMatch::createFromRequest() and that sole place is being removed in #2292217: ThemeNegotiator::determineActiveTheme() should not require a RouteMatch to be passed in.

dawehner’s picture

Just reviewed a bit. Classical example of doing too much in a match, honestly.

  1. +++ b/core/lib/Drupal/Core/Authentication/AuthenticationManager.php
    @@ -178,7 +179,7 @@ public function cleanup(Request $request) {
    -    $route = $request->attributes->get(RouteObjectInterface::ROUTE_OBJECT);
    +    $route = RouteMatch::createFromRequest($request)->getRouteObject();
    

    Can we somehow move the authentication after routing? AccessSubscriber::onKernelRequestAccessCheck happens after routing already

  2. +++ b/core/lib/Drupal/Core/Controller/DialogController.php
    @@ -93,7 +94,8 @@ public function dialog(Request $request, $_content, $modal = FALSE) {
    +    $title = isset($page_content['#title']) ? $page_content['#title'] : $this->titleResolver->getTitle($request, $route_match->getRouteObject());
    

    Can we just have two methods on the title resolver, one using the request + route?

  3. +++ b/core/lib/Drupal/Core/EventSubscriber/AccessSubscriber.php
    @@ -64,17 +65,16 @@ public function onKernelRequestAccessCheck(GetResponseEvent $event) {
    +    $route_match = RouteMatch::createFromRequest($request);
    ...
    -    if (!$request->attributes->has(RouteObjectInterface::ROUTE_OBJECT)) {
    -      // If no Route is available it is likely a static resource and access is
    -      // handled elsewhere.
    +    if (!$route_object = $route_match->getRouteObject()) {
    
    +++ b/core/lib/Drupal/Core/EventSubscriber/MaintenanceModeSubscriber.php
    @@ -121,6 +122,7 @@ public function onKernelRequestDetermineSiteStatus(GetResponseEvent $event) {
       public function onKernelRequestMaintenance(GetResponseEvent $event) {
         $request = $event->getRequest();
    +    $route_match = RouteMatch::createFromRequest($request);
    

    Does that mean that the route match should be maybe part of the response event (maybe as part of the request *hides*)

  4. +++ b/core/lib/Drupal/Core/Routing/AdminContext.php
    @@ -62,7 +61,7 @@ public function isAdminRoute(Route $route = NULL) {
       protected function getRouteFromRequest() {
         $request = $this->requestStack->getCurrentRequest();
         if ($request) {
    -      return $request->attributes->get(RouteObjectInterface::ROUTE_OBJECT);
    +      return RouteMatch::createFromRequest($request)->getRouteObject();
         }
       }
    

    Here we should inject the current route match as dependency, shouldn't we?

znerol’s picture

Can we somehow move the authentication after routing?

Yes we should, but that's not too easy mostly because maintenance mode, see #2286971: Remove dependency of current_user on request and authentication manager and its child-issues.

dawehner’s picture

I will extract a couple of the usages here in #2330363: Enhance the controller resolver to get a route match class

dawehner’s picture

chx’s picture

So according to #18 this issue should be set to postponed with a [pp-2] prefix?

tim.plunkett’s picture

Assigned: tim.plunkett » Unassigned

Still needs an issue summary. I'm not sure how much core has changed since #15, but there might be better ways to do this now.

dawehner’s picture

dawehner’s picture

Status: Needs work » Needs review
StatusFileSize
new52.04 KB

A hell lot of the instances got converted in the meantime.

This is a list of things which is not covered yet by this patch:

modules/webprofiler/src/Form/DatabaseFilterForm.php:68:    $profile = $this->getRequest()->attributes->get('profile');
modules/webprofiler/src/DataCollector/RequestDataCollector.php:32:      $_content = $request->attributes->get('_content');
modules/webprofiler/src/DataCollector/RequestDataCollector.php:39:          $request->attributes->get('_form'),
modules/page_manager/src/EventSubscriber/RouteParamContext.php:71:          $context->setContextValue($request->attributes->get($route_context_name));
modules/devel/src/Access/SwitchAccess.php:50:    $name = $request->attributes->get('name');
modules/devel/src/Form/SettingsForm.php:32:    $current_path = $request->attributes->get('_system_path');
core/lib/Drupal/Core/Entity/HtmlEntityFormController.php:46:    return $request->attributes->get('_entity_form');
core/lib/Drupal/Core/Entity/HtmlEntityFormController.php:75:      $entity = $request->attributes->get($entity_type);
core/lib/Drupal/Core/EventSubscriber/DefaultExceptionHtmlSubscriber.php:100:    $system_path = $request->attributes->get('_system_path');
core/lib/Drupal/Core/EventSubscriber/DefaultExceptionHtmlSubscriber.php:112:        $sub_request->attributes->set('exception', $request->attributes->get('exception'));
core/lib/Drupal/Core/EventSubscriber/ExceptionLoggingSubscriber.php:50:    $this->logger->get('access denied')->warning(String::checkPlain($request->attributes->get('_system_path')));
core/lib/Drupal/Core/EventSubscriber/ExceptionLoggingSubscriber.php:63:    $this->logger->get('page not found')->warning(String::checkPlain($request->attributes->get('_system_path')));
core/lib/Drupal/Core/EventSubscriber/ContentFormControllerSubscriber.php:68:    if ($form = $request->attributes->get('_form')) {
core/lib/Drupal/Core/EventSubscriber/ContentControllerSubscriber.php:51:    if (!$request->attributes->get('_format')) {
core/lib/Drupal/Core/Routing/RouteMatch.php:84:    if ($request->attributes->get(RouteObjectInterface::ROUTE_OBJECT)) {
core/lib/Drupal/Core/Routing/RouteMatch.php:86:      if ($raw = $request->attributes->get('_raw_variables')) {
core/lib/Drupal/Core/Routing/RouteMatch.php:90:        $request->attributes->get(RouteObjectInterface::ROUTE_NAME),
core/lib/Drupal/Core/Routing/RouteMatch.php:91:        $request->attributes->get(RouteObjectInterface::ROUTE_OBJECT),
core/lib/Drupal/Core/Routing/Enhancer/AuthenticationEnhancer.php:58:    $auth_provider_triggered = $request->attributes->get('_authentication_provider');
core/lib/Drupal/Core/Routing/RouteProvider.php:116:      $path = '/' . $request->attributes->get('_system_path');
core/lib/Drupal/Core/Routing/UrlMatcher.php:34:      $path = '/' . $request->attributes->get('_system_path');
core/lib/Drupal/Core/Form/FormSubmitter.php:142:      $url = $this->urlGenerator->generateFromPath($request->attributes->get('_system_path'), array(
core/lib/Drupal/Core/Controller/TitleResolver.php:60:      if (($raw_parameters = $request->attributes->get('_raw_variables'))) {
core/lib/Drupal/Core/Controller/ControllerResolver.php:92:    if (!$controller = $request->attributes->get('_controller')) {
core/lib/Drupal/Core/Controller/ControllerResolver.php:175:    if ($request->attributes->has('_raw_variables') && $raw = $request->attributes->get('_raw_variables')->all()) {
core/lib/Drupal/Core/Controller/HtmlFormController.php:45:    return $request->attributes->get('_form');
core/lib/Drupal/Core/Controller/ControllerResolverInterface.php:24:   *   The controller attribute like in $request->attributes->get('_controller')
core/modules/content_translation/content_translation.module:505:    \Drupal::service('content_translation.synchronizer')->synchronizeFields($entity, $entity->language()->getId(), $attributes->get('source_langcode'));
core/modules/views/src/Plugin/views/argument_default/Raw.php:96:    $path = $this->view->getRequest()->attributes->get('_system_path');
core/modules/system/src/Tests/HttpKernel/StackKernelIntegrationTest.php:48:    $this->assertEqual($request->attributes->get('_hello'), 'world');
core/modules/system/src/Tests/HttpKernel/StackKernelIntegrationTest.php:49:    $this->assertEqual($request->attributes->get('_previous_optional_argument'), 'test_argument');
core/modules/system/src/Plugin/Condition/RequestPath.php:146:    $path = $request->attributes->get('_system_path');
core/modules/system/tests/modules/httpkernel_test/src/HttpKernel/TestMiddleware.php:51:     $request->attributes->set('_previous_optional_argument', $request->attributes->get('_optional_argument'));
core/modules/system/tests/modules/theme_test/src/EventSubscriber/ThemeTestSubscriber.php:35:    $current_path = $request->attributes->get('_system_path');
core/modules/system/tests/modules/theme_test/src/EventSubscriber/ThemeTestSubscriber.php:60:    $current_path = $request->attributes->get('_system_path');
core/modules/rest/src/Access/CSRFAccessCheck.php:57:    $cookie = $request->attributes->get('_authentication_provider') == 'cookie';
core/vendor/symfony/http-foundation/Symfony/Component/HttpFoundation/RequestMatcher.php:161:            if (!preg_match('{'.$pattern.'}', $request->attributes->get($key))) {
core/vendor/symfony/http-foundation/Symfony/Component/HttpFoundation/Request.php:733:        if ($this !== $result = $this->attributes->get($key, $this, $deep)) {
core/vendor/symfony/http-foundation/Symfony/Component/HttpFoundation/Tests/RequestTest.php:42:        $this->assertEquals('bar', $request->attributes->get('foo'), '->initialize() takes an array of attributes as its third argument');
core/vendor/symfony/http-foundation/Symfony/Component/HttpFoundation/Tests/RequestTest.php:289:        $this->assertEquals('json', $dup->attributes->get('_format'));
core/vendor/symfony/http-kernel/Symfony/Component/HttpKernel/EventListener/LocaleListener.php:91:        if ($locale = $request->attributes->get('_locale')) {
core/vendor/symfony/http-kernel/Symfony/Component/HttpKernel/EventListener/FragmentListener.php:70:        $request->attributes->set('_route_params', array_replace($request->attributes->get('_route_params', array()), $attributes));
core/vendor/symfony/http-kernel/Symfony/Component/HttpKernel/Tests/EventListener/FragmentListenerTest.php:73:        $this->assertEquals(array('foo' => 'bar', '_controller' => 'foo'), $request->attributes->get('_route_params'));
core/vendor/symfony/http-kernel/Symfony/Component/HttpKernel/Tests/DataCollector/RequestDataCollectorTest.php:45:        $this->assertRegExp('/Resource\(stream#\d+\)/', $attributes->get('resource'));
core/vendor/symfony/http-kernel/Symfony/Component/HttpKernel/Tests/DataCollector/RequestDataCollectorTest.php:46:        $this->assertSame('Object(stdClass)', $attributes->get('object'));
core/vendor/symfony/http-kernel/Symfony/Component/HttpKernel/Controller/ControllerResolver.php:52:        if (!$controller = $request->attributes->get('_controller')) {

Status: Needs review » Needs work

The last submitted patch, 25: 2281619-25.patch, failed testing.

dawehner’s picture

Status: Needs work » Needs review
StatusFileSize
new52.05 KB
new501 bytes

Alright.

Status: Needs review » Needs work

The last submitted patch, 27: 2281619-27.patch, failed testing.

dawehner’s picture

Status: Needs work » Needs review
StatusFileSize
new3.13 KB
new54.49 KB

Let's see, how many failures are left.

Status: Needs review » Needs work

The last submitted patch, 29: 2281619-29.patch, failed testing.

dawehner’s picture

Status: Needs work » Needs review
StatusFileSize
new5.68 KB
new58.31 KB

Fixed some of the tests.

Status: Needs review » Needs work

The last submitted patch, 31: 2281619-31.patch, failed testing.

dawehner’s picture

Status: Needs work » Needs review
StatusFileSize
new1.06 KB
new58.66 KB

.

Status: Needs review » Needs work

The last submitted patch, 33: 2281619-33.patch, failed testing.

dawehner’s picture

Status: Needs work » Needs review
StatusFileSize
new749 bytes
new58.66 KB

ups, my fail.

amateescu’s picture

Status: Needs review » Needs work
  1. +++ b/core/lib/Drupal/Core/Menu/LocalActionDefault.php
    @@ -92,6 +93,7 @@ public function getRouteParameters(Request $request) {
    +    $route_match = RouteMatch::createFromRequest($request);
    

    @effulgentsia says in #16 that RouteMatch::createFromRequest() is not a good pattern to use, so I wonder if we should inject the $route_match service instead?

  2. +++ b/core/lib/Drupal/Core/Menu/LocalTaskManager.php
    @@ -341,10 +342,11 @@ protected function isRouteActive($current_route_name, $route_name, $route_parame
    +    $route_match = RouteMatch::createFromRequest($request);
    

    Same here.

  3. +++ b/core/modules/block_content/src/Plugin/Menu/LocalAction/BlockContentAddLocalAction.php
    @@ -21,16 +22,19 @@ class BlockContentAddLocalAction extends LocalActionDefault {
    +    $route_match = RouteMatch::createFromRequest($request);
    

    This wouldn't be needed if we do 1., because we'd have the route match available from the parent class.

  4. +++ b/core/modules/config_translation/src/ConfigEntityMapper.php
    
    +++ b/core/modules/config_translation/src/ConfigMapperInterface.php
    
    +++ b/core/modules/config_translation/src/ConfigNamesMapper.php
    
    +++ b/core/modules/config_translation/tests/src/Unit/ConfigNamesMapperTest.php
    

    Maybe it would be easier if we leave all the Config*Mapper changes to #2295255: Convert ConfigMapperInterface::populateFromRequest() to use RouteMatch?

  5. +++ b/core/modules/menu_ui/src/Plugin/Menu/LocalAction/MenuLinkAdd.php
    @@ -21,15 +22,11 @@ class MenuLinkAdd extends LocalActionDefault {
    +    $route_match = RouteMatch::createFromRequest($request);
    

    Same as 1. and 3.

Also related to the points above, the change notice for RouteMatch (https://www.drupal.org/node/2295317) lists If you have a request available, you can just RouteMatch::createFromRequest($request). as the first way of using it. Based on #16, should we update the change notice to say that we need to use RouteMatch::createFromRequest($request) only when we have a $request and no way of injecting the route match service? I'd be really curious to see an example of that.

dawehner’s picture

Okay, let's first figure out #2294157: Switch getOptions() and getRouteParameters() within LocalActionInterface and LocalTaskInterface to use RouteMatch as it deals with the fact whether / how to use the route match.

dawehner’s picture

Status: Needs work » Postponed

Update this issue to be postponed

dawehner’s picture

Status: Postponed » Needs review
StatusFileSize
new48.17 KB

Alright, a recent reroll.

dawehner’s picture

Issue summary: View changes

Worked on a proper issue summary

amateescu’s picture

+++ b/core/modules/field_ui/src/DisplayOverviewBase.php
@@ -190,7 +190,7 @@ public function buildForm(array $form, FormStateInterface $form_state, $entity_t
-      $bundle = $bundle ?: $this->getRequest()->attributes->get('_raw_variables')->get($this->bundleEntityTypeId);
+      $bundle = $bundle ?: $this->getRouteMatch()->getRawParameter($this->bundleEntityTypeId);

I'm also removing this one in #2094499: Convert "Manage (form) display" forms to be the official entity edit forms for EntityView[Form]Display objects :)

dawehner’s picture

Nice, so RTBC ? ;)

amateescu’s picture

Status: Needs review » Needs work

I was more like hoping you would prefer to keep that hunk out of the patch, but apparently not :P

It looks like #36.4 is still not done. And here's another in-depth review:

  1. +++ b/core/lib/Drupal/Core/Routing/AdminContext.php
    @@ -24,13 +24,20 @@ class AdminContext {
       protected $requestStack;
    

    Looks like we can remove this member now.

  2. +++ b/core/modules/content_translation/src/Controller/ContentTranslationController.php
    @@ -10,6 +10,7 @@
     use Symfony\Component\HttpFoundation\Request;
    

    Pretty sure this is unused now :)

  3. +++ b/core/modules/field_ui/src/Controller/FieldConfigListController.php
    @@ -22,18 +23,17 @@ class FieldConfigListController extends EntityListController {
    +   * @param \Drupal\Core\Routing\RouteMatchInterface $route_match
    +   *   The current route match.
    +   * @return array A render array as expected by drupal_render().
    +   * A render array as expected by drupal_render().
    

    Something went wrong here...

  4. +++ b/core/modules/rest/src/RequestHandler.php
    @@ -31,11 +31,13 @@ class RequestHandler implements ContainerAwareInterface {
    +   * @return \Symfony\Component\HttpFoundation\Response The response object.
    +   * The response object.
    

    Same here.

  5. +++ b/core/modules/system/tests/modules/entity_test/src/Controller/EntityTestController.php
    @@ -10,6 +10,8 @@
    +use Drupal\Core\Routing\RouteMatch;
    

    This one doesn't seem to be needed.

  6. +++ b/core/modules/system/tests/modules/form_test/src/FormTestControllerObject.php
    @@ -10,6 +10,7 @@
    +use Symfony\Component\HttpFoundation\Request;
    
    @@ -34,11 +35,11 @@ public static function create(ContainerInterface $container) {
    -  public function buildForm(array $form, FormStateInterface $form_state, $custom_attributes = NULL) {
    +  public function buildForm(array $form, FormStateInterface $form_state, Request $request = NULL, $custom_attributes = NULL) {
    ...
    -    $form['request_attribute']['#markup'] = $this->getRequest()->attributes->get('request_attribute');
    +    $form['request_attribute']['#markup'] = $request->attributes->get('request_attribute');
    

    I realize this is test code but it tests exactly the thing we're trying to move away from. Is it worth keeping it?

  7. +++ b/core/modules/system/tests/modules/paramconverter_test/src/TestControllers.php
    @@ -8,6 +8,7 @@
    +use Drupal\Core\Routing\RouteMatch;
    

    Not used?

  8. +++ b/core/modules/user/src/Plugin/Block/UserLoginBlock.php
    @@ -30,7 +30,7 @@ class UserLoginBlock extends BlockBase {
    -    $route_name = \Drupal::request()->attributes->get(RouteObjectInterface::ROUTE_NAME);
    +    $route_name = \Drupal::routeMatch()->getRouteName();
    

    In all the other places you injected the current_route_match service, any reason for not doing it here too?

  9. +++ b/core/modules/user/src/Plugin/LanguageNegotiation/LanguageNegotiationUserAdmin.php
    @@ -10,6 +10,7 @@
    +use Drupal\Core\Routing\RouteMatch;
    
    @@ -117,7 +118,8 @@ protected function isAdminPath(Request $request) {
    -      if (!$route_object = $request->attributes->get(RouteObjectInterface::ROUTE_OBJECT)) {
    +      $route_match = RouteMatch::createFromRequest($request);
    +      if (!$route_object = $route_match->getRouteObject()) {
    

    This plugin already extends ContainerFactoryPluginInterface, why not inject the service instead?

  10. +++ b/core/tests/Drupal/Tests/Core/Menu/LocalTaskDefaultTest.php
    @@ -11,6 +11,7 @@
    +use Symfony\Component\DependencyInjection\ParameterBag\ParameterBag;
    

    Unrelated I think.

dawehner’s picture

Status: Needs work » Needs review
StatusFileSize
new20.68 KB
new48.87 KB

Thank you for your review!!!

I'm also removing this one in #2094499: Convert "Manage (form) display" forms to be the official entity edit forms for EntityView[Form]Display objects :)

Alright, let's get rid of that hunk

Looks like we can remove this member now.

Good catch!

Pretty sure this is unused now :)

Fair

I realize this is test code but it tests exactly the thing we're trying to move away from. Is it worth keeping it?

In terms of test coverage it makes sense to convert to the more often used API.

In all the other places you injected the current_route_match service, any reason for not doing it here too?

Fixed that.

This plugin already extends ContainerFactoryPluginInterface, why not inject the service instead?

Well, the problem is that you need the route match for the passed in request. Expanded the stacked route match interface to allow that.

Unrelated I think.

Yup

Maybe it would be easier if we leave all the Config*Mapper changes to #2295255: Convert ConfigMapperInterface::populateFromRequest() to use RouteMatch?

Given that the other issue doesn't have any proper patch yet,

Maybe it would be easier if we leave all the Config*Mapper changes to #2295255: Convert ConfigMapperInterface::populateFromRequest() to use RouteMatch?

Okay, then let's do that.

Status: Needs review » Needs work

The last submitted patch, 44: 2281619-44.patch, failed testing.

dawehner’s picture

Status: Needs work » Needs review
StatusFileSize
new1.28 KB
new49.45 KB

Okay, breaking the login form is a bad idea :)

Status: Needs review » Needs work

The last submitted patch, 46: 2281619-46.patch, failed testing.

amateescu’s picture

Okay, breaking the login form is a bad idea :)

Yes, don't do that! :)

The last remaining test fail is quite interesting and I think it shows a flaw in the way (or timing) RequestMatch objects are created, because they don't have custom request attributes added by an event. Now I'm glad I brought up #43.6.

dawehner’s picture

Status: Needs work » Needs review
StatusFileSize
new1.44 KB
new49.47 KB

Well, to be clear here, the route match just contains parameters which are part of the URL, not arbitrary request attributes.

In this test we do update arbitrary request attributes, so well let's keep it, the test ensure that you can inject the request object.

amateescu’s picture

Status: Needs review » Reviewed & tested by the community

Right, that explanation makes sense. I found a few more really small nitpicks which are not worth blocking a critical and can be fixed on commit if you don't want to roll a new patch.

  1. +++ b/core/lib/Drupal/Core/Routing/StackedRouteMatchInterface.php
    @@ -6,6 +6,7 @@
     namespace Drupal\Core\Routing;
    +use Symfony\Component\HttpFoundation\Request;
    

    Missing newline.

  2. +++ b/core/lib/Drupal/Core/Routing/StackedRouteMatchInterface.php
    @@ -36,5 +37,14 @@ public function getMasterRouteMatch();
    +   * @param \Symfony\Component\HttpFoundation\Request
    +   *   The request.
    +   * @return \Drupal\Core\Routing\RouteMatchInterface|NULL
    +   *   THe matching route match, or NULL if there is no matching one.
    

    Same here.

  3. +++ b/core/modules/user/src/Plugin/Block/UserLoginBlock.php
    @@ -22,15 +24,68 @@
    +  /**
    +   * Creates an instance of the plugin.
    +   *
    +   * @param \Symfony\Component\DependencyInjection\ContainerInterface $container
    +   *   The container to pull out services used in the plugin.
    +   * @param array $configuration
    +   *   A configuration array containing information about the plugin instance.
    +   * @param string $plugin_id
    +   *   The plugin ID for the plugin instance.
    +   * @param mixed $plugin_definition
    +   *   The plugin implementation definition.
    +   *
    +   * @return static
    +   *   Returns an instance of this plugin.
    +   */
    +  public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
    

    Can be just {@inheritdoc}.

dawehner’s picture

StatusFileSize
new48.97 KB
new1.75 KB

Thank you for the RTBC, but there is no reason to not fix these nitpicks.

Missing newline.

Don't blame the patch, blame storm :)

alexpott’s picture

Status: Reviewed & tested by the community » Needs work
  1. +++ b/core/core.services.yml
    index d5193e7..febffd9 100644
    --- a/core/lib/Drupal/Core/Controller/ControllerResolver.php
    
    --- a/core/lib/Drupal/Core/Controller/ControllerResolver.php
    +++ b/core/lib/Drupal/Core/Controller/ControllerResolver.php
    

    Talking @dawehener in IRC he says the changes to this are a bug - do we need to add tests for this?

  2. +++ b/core/lib/Drupal/Core/Controller/ControllerResolver.php
    @@ -166,21 +170,6 @@ protected function doGetArguments(Request $request, $controller, array $paramete
    -    // The parameter converter overrides the raw request attributes with the
    -    // upcasted objects. However, it keeps a backup copy of the original, raw
    -    // values in a special request attribute ('_raw_variables'). If a controller
    -    // argument has a type hint, we pass it the upcasted object, otherwise we
    -    // pass it the original, raw value.
    

    Should we not keep the comment?

dawehner’s picture

Status: Needs work » Reviewed & tested by the community

Talking @dawehener in IRC he says the changes to this are a bug - do we need to add tests for this?

Note: ControllerResolverTest is changed as part of this patch.

Should we not keep the comment?

It is not valid anymore ...

alexpott’s picture

Status: Reviewed & tested by the community » Fixed

Thanks @dawehner.

Committed 1e08b50 and pushed to 8.0.x. Thanks!

  • alexpott committed 1e08b50 on 8.0.x
    Issue #2281619 by dawehner, tim.plunkett: Convert most direct usages...
dawehner’s picture

Thank you a ton alex!

amateescu’s picture

A bit sad to see that the fancy new "Credit & committing" stuff is still not used at its full potential (e.g. for reviewers)..

xjm’s picture

@amateescu, one issue is that the form is pure JS (it looks like you can save a list of who to credit, but actually nothing is saved). I think there's an issue to improve this but I wasn't able to locate it.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.

cilefen’s picture

#2830631: Remove code that tries to use _raw_variables for route argument resolution as it does not work is saying the changes to ControllerResolver in terms of not using the raw parameters constitutes a bug.