Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
When I install Drupal 8 in s subdirectory and use the URLgenerator to create a path with the subdir name repeated 2x:
like: http://127.0.0.1:8082/subdir-d8/subdir-d8/admin/structure/views/add
The generator is being called like on a route name (string):
$this->generator->generate($this->getRouteName());
the generator was pulled from the DIC container in a plugin create() method:
$container->get('url_generator')
This is causing test fails in #1981644: Figure out how to deal with 'title/title callback' and blocking progress on other issues. That patch can be used to reproduce the issue.
Comment | File | Size | Author |
---|---|---|---|
#44 | drupal-2031353-39-43.increment.txt | 890 bytes | pwolanin |
#43 | drupal-2031353-43.patch | 12.07 KB | pwolanin |
#39 | drupal-2031353-39.patch | 11.99 KB | pwolanin |
#39 | drupal-2031353-36-39.increment.txt | 718 bytes | pwolanin |
#36 | drupal-2031353-36.patch | 12.06 KB | pwolanin |
Comments
Comment #1
pwolanin CreditAttribution: pwolanin commentedSo the bug seems to be that the output of the generator is getting passed back to the url() function which appends the base path again.
I'm not sure if the answer is "don't do that" or if we should be testing for that
Comment #2
pwolanin CreditAttribution: pwolanin commentedcould maybe fix like this?
Comment #3
pwolanin CreditAttribution: pwolanin commentedWell, I'm not sure that's right either - for now I'm stripping the base URL back of the result of ->generate(), but perhaps we need a new method added to the interface to support returning just the Drupal path for a route?
Comment #4
dawehnerComment #5
pwolanin CreditAttribution: pwolanin commenteddo we not need processPath? I was assuming that's where values like {node} would get replaced.
Comment #6
dawehnerLet's also add the path processor function and add unit tests
Comment #7
dawehnerReplaced to trim the end and the start.
Comment #8
dawehnerComment #9
pwolanin CreditAttribution: pwolanin commentedRTBC after minor code comment and whitespace fixes.
Comment #10
dawehnerFixed documents based upon your latest changes.
Comment #11
alexpottLet's not do this... things that needs to trim the result of getPathFromRoute() can do it themselves...
Comment #12
pwolanin CreditAttribution: pwolanin commentedPer IRC discussion w/ alexpott. A Drupal path should not have leading or trailing spaces.
So, we can have a commonly used protected method to avoid trimming and then adding back the '/'.
Comment #13
dawehnerI can't think of a better name for now, but as it is internally, it feels great.
Comment #14
katbailey CreditAttribution: katbailey commentedSome logic seems to have gone askew in the moving around here - the
$scheme_req
variable which we use to store$route_requirements['_scheme']
before unsetting that from the $route_requirements array, is now getting set (or not) in thegetUrlPathFromRoute()
method, but being checked in thegenerate()
method, where it will never be set.It may well be that we never use $route_requirements['_scheme'] but we still need to fix the logic here as it doesn't make sense.
Comment #15
katbailey CreditAttribution: katbailey commentedI've added a test for the 'scheme' route requirement. The test passes in HEAD but fails with this patch.
I hope it's ok that I also took this opportunity to rework the UrlGeneratorTest a little too as it was getting pretty unwieldy.
Setting to needs review just to show the test failure.
Comment #16
katbailey CreditAttribution: katbailey commentedComment #17
dawehnerThanks for spotting the problem!
Let's extract the logic to get the route and use that information to build a proper url.
Comment #19
pwolanin CreditAttribution: pwolanin commented#17: drupal-2031353-17.patch queued for re-testing.
Comment #20
pwolanin CreditAttribution: pwolanin commentedsmall tweak to avoid calling getroute() 2x.
Comment #22
pwolanin CreditAttribution: pwolanin commentedWeird - that should have been a no-op change.
Comment #23
pwolanin CreditAttribution: pwolanin commentedAh, just missing the name in context now, which is only used for error messages, so this passes the path instead (oddly the route seems not to know its own name). Also, it looks like before this would have been a bit broken if you passed in an actual route object as that param.
Comment #25
pwolanin CreditAttribution: pwolanin commented#23: drupal-2031353-23.patch queued for re-testing.
Comment #26
dawehnerOpened an upstream bug report: https://github.com/symfony/symfony/issues/8394
Comment #27
dawehnerIssue got moved to https://github.com/symfony-cmf/Routing/issues/65
Comment #28
YesCT CreditAttribution: YesCT commentedThis issue was RTBC and passing tests on July 1, the beginning of API freeze.
Comment #29
msonnabaum CreditAttribution: msonnabaum commentedIt's not immediately clear to me that getUrlPathFromRoute returns the exact same thing as getPathFromRoute, just with slashes added.
Changing the name isn't critical since it's not a public method, but could we maybe document that it exists to workaround what symfony's route returns?
Comment #30
alexpottI agree we need to clear this up a bit... what is the difference between
Gets the internal path of a route.
andGets the path of a route
??Maybe the following will help us come up with something... I'm not 100% convinced myself :)
How about
getUrlFromRoute()
for the public function? And the protected functiongetPathFromRoute
?The docs for
getUrlFromRoute()
could be something likeGets the relative url for a route
The docs for
getPathFromRoute()
could be something likeGets the path of a route
Comment #31
dawehnerMh, doesn't the url() method give you a path with a prefix, so exactly what we want to not have on the longrun?
Comment #32
dawehnerwell, getUrlFromRoute is pointless actually, because that is exactly the usecase of the generate method, or?
Comment #33
pwolanin CreditAttribution: pwolanin commentedWe are using it as part of the internal flow of generate, right? It's not pointless since it doesn't include any prefix (e.g. language) or alias.
We could call it internalPathWithSlashes() for all I care - it mostly exists since AlexPott didn't like stripping and then adding back the slashes for the generate flow.
Comment #34
pwolanin CreditAttribution: pwolanin commented@alexpott - I think you are confusing the issue.
The one and only thing we need to add to the public methods is a way to get the Drupal (internal) path for a route. That's what's missing currently.
We can bikeshed the name of the protected function, but it really doesn't matter - we can change it in a follow-up if it really bothers someone.
Comment #35
pwolanin CreditAttribution: pwolanin commentedThis think this is wrong - we don't want to call processPath() when we are looking for the system path, since that will potentially add a language prefix or do other things we don't want.
Comment #36
pwolanin CreditAttribution: pwolanin commentedRight, and I think the test was wrong - it was looking for the path alias, not the path.
Comment #37
katbailey CreditAttribution: katbailey commentedThis looks good to me.
Comment #38
chx CreditAttribution: chx commentedMeh.
$path = preg_replace('/\?.*/', '', $path);
Comment #39
pwolanin CreditAttribution: pwolanin commentedfine that way too.
Comment #40
chx CreditAttribution: chx commentedThanks
Comment #41
dawehnerOkay, so we save 3 lines of code with a regular expression. Whether this is easier to read or not is up to the reader. Can we please also just document what this
regex itself is doing here?
Comment #42
dawehnerback to rtbc
Comment #43
pwolanin CreditAttribution: pwolanin commentedjust improves the code comment.
Comment #44
pwolanin CreditAttribution: pwolanin commentedforgot to attach the incremental diff
Comment #45
dawehnerThank you very much!
Comment #46
alexpottCommitted 486f5d0 and pushed to 8.x. Thanks!
We still need a change notice for #1888424: Make Drupal's URL generation logic available to HttpKernel, and minimize code repetition/divergence and this should be part of it!
Comment #47
pwolanin CreditAttribution: pwolanin commentedmaking a start on the change notice at https://drupal.org/node/2046643
Comment #48
pwolanin CreditAttribution: pwolanin commentedchange notice is reasonably done.
Comment #49
jibranFixing title.