Closed (fixed)
Project:
Drupal core
Version:
8.0.x-dev
Component:
routing system
Priority:
Major
Category:
Bug report
Assigned:
Unassigned
Issue tags:
Reporter:
Created:
29 Jun 2013 at 17:53 UTC
Updated:
29 Jul 2014 at 22:36 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #1
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 commentedcould maybe fix like this?
Comment #3
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 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 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 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 commentedSome logic seems to have gone askew in the moving around here - the
$scheme_reqvariable 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 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 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 commented#17: drupal-2031353-17.patch queued for re-testing.
Comment #20
pwolanin commentedsmall tweak to avoid calling getroute() 2x.
Comment #22
pwolanin commentedWeird - that should have been a no-op change.
Comment #23
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 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 commentedThis issue was RTBC and passing tests on July 1, the beginning of API freeze.
Comment #29
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 routeThe docs for
getPathFromRoute()could be something likeGets the path of a routeComment #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 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 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 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 commentedRight, and I think the test was wrong - it was looking for the path alias, not the path.
Comment #37
katbailey commentedThis looks good to me.
Comment #38
chx commentedMeh.
$path = preg_replace('/\?.*/', '', $path);Comment #39
pwolanin commentedfine that way too.
Comment #40
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 commentedjust improves the code comment.
Comment #44
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 commentedmaking a start on the change notice at https://drupal.org/node/2046643
Comment #48
pwolanin commentedchange notice is reasonably done.
Comment #49
jibranFixing title.