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.
Problem/Motivation
We have many url-related helper functions in core, that kill unit-testing..e.g the new RedrectResponseSubscriber went in without unit tests because it calls those procedural helpers.
Proposed resolution
Group all url related functions i a Url
Component under Drupal\Component\utility\Url
.
There is an existing UrlValidator component, which would now make sense to merge inside the Url one.
drupal_get_query_parameters() => Url::filterQueryParameters()
drupal_get_query_array() => Url::getArray()
drupal_parse_url() => Url::parse()
drupal_encode_path() => Url::encodePath()
_external_url_is_local() => Url::externalIsLocal()
url_is_external() => Url::isExternal()
Remaining tasks
We got a green patch, commit it
User interface changes
None
API changes
The old procedural functions will stay as a wrapper, but will be marked as deprecated. Url component should be called directly
Comment | File | Size | Author |
---|---|---|---|
#48 | 2010024-48.patch | 43.09 KB | damiankloip |
#45 | vdc-2010024-45.patch | 43.09 KB | dawehner |
#45 | interdiff.txt | 1.94 KB | dawehner |
#44 | drupal-2010024-44.patch | 43.71 KB | dawehner |
#44 | interdiff.txt | 3.57 KB | dawehner |
Comments
Comment #1
dawehnerLet's start.
I think we should though try to rely more on just the php functions and helper stuff from symfony.
Comment #2
Crell CreditAttribution: Crell commentedWhy? No one has ever explained to me why we have to do something different here.
This is too small to bother making a utility function. Really.
Comment #3
dawehnerWell, I think we can replace drupal_get_query_array() by this function completely without an issue but some backward-compatible-layer would be great to make some progress here.
I don't know either, but maybe it is written somewhere on #578520: Make $query in url() only accept an array or is just not the case anymore in Drupal 8.
Comment #4
Damien Tournoud CreditAttribution: Damien Tournoud commentedrawurlencode()
is RFC3986 compliant, and as a consequence RFC3987 compliant. The latter defines the required format of "URLs" in HTML5.urlencode()
is almost the same asrawurlencode()
, except that it encodes spaces as"+"
instead of"%20"
. This makes its result non compliant to RFC3986 and as a consequence non compliant to RFC3987 and as a consequence not valid as a "URL" in HTML5.That said,
http_build_query()
has an optional$enc_type
parameter since PHP 5.4, that allows it to generate URLs compliant with HTML5.Comment #5
Crell CreditAttribution: Crell commentedSigh. If we need it essentially as a BC wrapper, then we should document that (per #4) and if on PHP 5.4 just use http_build_query() directly. That way when we eventually move to just 5.4 we can drop this function entirely.
Comment #6
dawehnerThanks for the explanation!
Comment #8
dawehner#6: drupal-2010024-6.patch queued for re-testing.
Comment #10
dawehnerNow that the url generator went in ... should this live on the url generator?
Comment #11
katbailey CreditAttribution: katbailey commentedThe generator already has an httpBuildQuery() method:
http://drupalcode.org/project/drupal.git/blob/2432c02138861423b7db365265...
Comment #12
ParisLiakos CreditAttribution: ParisLiakos commentedImo drupal_parse_url and httpBuildQuery should be together in one component
Comment #13
dawehnerWhat about drupal_get_query_array?
Comment #14
ParisLiakos CreditAttribution: ParisLiakos commentedthat too..anything that has to do with query/url besides generating should be in the same component...so that people can find them immediately..maybe merge UrlValidator too
Comment #15
damiankloip CreditAttribution: damiankloip commentedOk, how about we move the whole lot of methods into one Url class? This patch is still rough around the edges, be warned.
Comment #17
dawehnerNeed some docs.
Comment #18
ParisLiakos CreditAttribution: ParisLiakos commentedretitling
Comment #19
Crell CreditAttribution: Crell commentedNo way. $query should be required. Code in Component should not be touching global anything.
Comment #20
damiankloip CreditAttribution: damiankloip commentedI said be warned, and rough around the edges. I thought it was pretty obvious I just quickly c & p'ed a few things.
Comment #21
damiankloip CreditAttribution: damiankloip commentedok, I've moved some more things. I'm not sure about moving _external_url_is_local, as it needs the base path. Thoughts?
I also spoke to Paris about merging in #2020811: Move _external_url_is_local and url_is_external to UrlValidator and putting everything in this Url class.
Comment #23
damiankloip CreditAttribution: damiankloip commentedSeems the version_compare logic was backwards.
Comment #25
damiankloip CreditAttribution: damiankloip commentedSorry, elementary error there.
Comment #26
dawehnerCommented out?
There should be a @deprecated tag on that as well.
While here we could do Drupal::request()->query->all() but this is optional, i think.
Would be cool to adapt this comment.
Maybe another one which makes sense to change.
"THe", must be important.
An @see for the url would be nice. I guess we have to kill the references to the http query class.
Commented out?
Comment #28
ParisLiakos CreditAttribution: ParisLiakos commentedyou can see my patch over @ #2020811: Move _external_url_is_local and url_is_external to UrlValidator
Just add one more parameter. $base_url
Comment #29
damiankloip CreditAttribution: damiankloip commentedThanks for the review! Yep, accidentally left that line commented out :) Added the @see, @deprecated tags, and fixed up the other part of the doc block (I think). I also moved everything from UrlValidatorTest to UrlTest.
I have left check_url() for now, as it uses check plains the url string. Do you think we should move that into this class too? and just rely on string? or keep it out of there?
Comment #30
damiankloip CreditAttribution: damiankloip commentedSorry Paris, I x posted with your comment, here is a new patch with that rolled in.
Comment #31
ParisLiakos CreditAttribution: ParisLiakos commentedGreat, looks awesome
just a thing which will make bot fail probably
you dont return the value anymore
Thank you!
Comment #33
damiankloip CreditAttribution: damiankloip commentedThat'll do it!
Comment #34
damiankloip CreditAttribution: damiankloip commentedComment #35
dawehnerReally nice!!
It would be cool to use the request object here as well.
Sorry, but this referes to the old method.
Comment #36
damiankloip CreditAttribution: damiankloip commentedThank you, I changed drupal_get_destination to use the Request object instead. I also changed all the data provider docblocks, so they are consistent.
Comment #37
dawehnerPerfect!
Comment #38
ParisLiakos CreditAttribution: ParisLiakos commentedone $_GET escaped:P die!
heh
damiankloip++
Comment #39
alexpott@todo is not an accpetable issue summary :D
Comment #40
ParisLiakos CreditAttribution: ParisLiakos commentedUpdated issue summary...not sure what the status should be...letss put it in needs review
Comment #40.0
ParisLiakos CreditAttribution: ParisLiakos commentedProper issue summary
Comment #41
Crell CreditAttribution: Crell commentedBack to RTBC. I couldn't find anything in the new class that violated Component rules, so...
Comment #42
dawehnerThank you for writing an issue summary!
Comment #43
alexpottAs Url::getArray just calls the native PHP function we just use this instead so lets deprecate this for parse_str and not Just Another Wrapper (tm)
Comment #44
dawehnerLet's do that and get rid of the problematic issue at the same time.
There are tests failures with php 5.4, so it seems to be that http_build_query() can't be used
Comment #45
dawehnerLet's remove the actual code as well.
Comment #46
ParisLiakos CreditAttribution: ParisLiakos commentedyeah i can reproduce the failures in PHP 5.4, so yes lets just stick with the old code for now.
removing the wrapper is awesome though!
thanks:)
Comment #47
alexpottNeeds a reroll
Comment #48
damiankloip CreditAttribution: damiankloip commentedPure git reroll.
Comment #49
alexpottCommitted 91c32e3 and pushed to 8.x. Thanks!
We need a change notice to announce the removal of
drupal_get_query_array
and to tell people to use the built inparse_str()
Comment #50
ParisLiakos CreditAttribution: ParisLiakos commentedyay!
Comment #51
dlu CreditAttribution: dlu commentedMoved to routing system per #2050763-16: Refine "base system" component (notes on refactoring of "base system" category here: https://docs.google.com/a/acquia.com/spreadsheet/ccc?key=0AusehVccVSq2dF...).
Comment #52
dawehnerHere is one: https://drupal.org/node/2079005
Comment #53
Crell CreditAttribution: Crell commentedI shifted the list of functions to the body, not the title, so that it's actually readable. :-) You should still be able to search by the function name, though. We're good.
Comment #54.0
(not verified) CreditAttribution: commentedtypo
Comment #55
David_Rothstein CreditAttribution: David_Rothstein commentedThis is still missing from the change notice (https://drupal.org/node/2079005).
(Coming here from #2143461: drupal_get_query_array encodes not enough if query parameter contains a equal sign (=); was trying to decide if that patch needed to go into Drupal 8 too and had to read this issue rather than the change notice to figure out that it didn't...)
Comment #56
star-szrTagging for the task of updating the change record as described in #55.
Comment #57
SebCorbin CreditAttribution: SebCorbin commentedChange record updated.
Comment #58
SebCorbin CreditAttribution: SebCorbin commentedRemoving tags
Comment #59
Crell CreditAttribution: Crell commentedComment #60
star-szrThanks @SebCorbin! I think we can keep this tag for posterity.