Problem/Motivation

I'm not 100% sure how the routing system treats two routes with /something and /something/{optional_argument} but they are not the same, and going to /something uses the route without the parameter.

So I think page manager shouldn't drop them when looking for an existing route. Same is likely true for views in core where this code is coming from.

My problem is at least as much caused by our incorrect patch in #2352959: Arguments step -1: Make it possible to generate paths with it. which always makes arguments optional, but I have a crazy effect that depending on the order of pages in the route alter event (which is somehow different on a full cache clear vs. only a route rebuild or maybe there is more than one call... no idea why, just happens on one environment (production, of course..)).

But I'm opening this issue since I think it's wrong anyway. We also don't remove parameters from the current route/path, so it's inconsistent anyway.

Proposed resolution

Remaining tasks

User interface changes

API changes

Data model changes

Comments

Berdir created an issue. See original summary.

berdir’s picture

Status: Active » Needs review
StatusFileSize
new729 bytes

What I'm proposing is this.

And to summarize, the router doesn't treat /something/{optional_argument} the as /something (as in, you can have both routes in your system, it will just never use the one with the optional argument if none is given), so I don't see a reason why page manager (or views) should.

tim.plunkett’s picture

Issue tags: +Needs tests

Okay, makes sense to me.

tim.plunkett’s picture

berdir’s picture

Notes for writing a test for this:

Define a test module with an optional route argument, or find a test module that provides that, create a page that is identical except that argument.. make sure both routes are defined and are accessible.

giancarlosotelo’s picture

Rebase was needed.

As for as I understand I have to create a page without '%' and assert that the page works. I am doing that but I don't know why the only test is not failing. Probably this was already fixed or I am wrong, so I need some feedback.

juanse254’s picture

Status: Needs review » Needs work

The test-only is passing, something not right there.

berdir’s picture

Yes, you need two routes, see the examples in the issue summary (/something and /something/{placeholder}). The second needs to be pre-defined in a test module, as I wrote.

giancarlosotelo’s picture

Status: Needs work » Needs review
StatusFileSize
new1.15 KB
new2.53 KB

I was a bit confused with the test module. So here is the test only and complete patch.

tim.plunkett’s picture

Status: Needs review » Needs work
Issue tags: -Needs tests
+++ b/tests/modules/page_manager_test/page_manager_test.routing.yml
@@ -2,5 +2,6 @@ page_manager_test.page_view:
+    page: 'something'

Missing this change in the test-only patch, hopefully that's why it didn't fail?

giancarlosotelo’s picture

Status: Needs work » Needs review
StatusFileSize
new1.7 KB

Yes, the default parameter was missing.

Status: Needs review » Needs work

The last submitted patch, 11: without-defaults-removal-2549997-11-ONLYTEST.patch, failed testing.

tim.plunkett’s picture

Status: Needs work » Fixed

Great. Adding unit test coverage as well:

diff --git a/tests/src/Unit/PageManagerRoutesTest.php b/tests/src/Unit/PageManagerRoutesTest.php
index 0846303..2194e1d 100644
--- a/tests/src/Unit/PageManagerRoutesTest.php
+++ b/tests/src/Unit/PageManagerRoutesTest.php
@@ -192,7 +192,7 @@ public function testAlterRoutesOverrideExisting($page_path, $existing_route_path
     $this->cacheTagsInvalidator->invalidateTags(["page_manager_route_name:$route_name"])->shouldBeCalledTimes(1);
 
     $collection = new RouteCollection();
-    $collection->add($route_name, new Route($existing_route_path, [], [], ['parameters' => ['foo' => 'bar']]));
+    $collection->add($route_name, new Route($existing_route_path, ['default_exists' => 'default_value'], [], ['parameters' => ['foo' => 'bar']]));
     $route_event = new RouteBuildEvent($collection);
     $this->routeSubscriber->onAlterRoutes($route_event);
 
@@ -227,6 +227,8 @@ public function providerTestAlterRoutesOverrideExisting() {
     $data['no_slug'] = ['/test_route', '/test_route'];
     $data['slug'] = ['/test_route/{test_route}', '/test_route/{test_route}'];
     $data['placeholder'] = ['/test_route/%', '/test_route/{test_route}'];
+    $data['slug_with_default'] = ['/test_route/{default_exists}', '/test_route/{default_exists}'];
+    $data['placeholder_with_default'] = ['/test_route/%', '/test_route/{default_exists}'];
     return $data;
   }
 

Status: Fixed » Needs work

The last submitted patch, 11: without-defaults-removal-2549997-11-ONLYTEST.patch, failed testing.

tim.plunkett’s picture

Status: Needs work » Fixed

Status: Fixed » Closed (fixed)

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