Problem/Motivation
hook_help API example contains a deprecated call to Drupal::url() (ref: #2730625: hook_help API example contains a deprecated call to Drupal::url()
Proposed resolution
create a single patch targeting the 'big-picture' quoted here (from ref above) ...
In terms of "Getting the big picture" we are only talking about a couple lines of code and 164 calls to Drupal::url() per the api.
Remaining tasks
wrt a patch --> plan it, write it, test it, run it
User interface changes
To be determined (TBD)
API changes
As per the "Deprecated" notice on public static function Drupal::url
Drupal::url(...) is deprecated and we should us Url::fromRoute(...)->toString() instead.
this means ...
array(':blocks' => \Drupal::url('block.admin_display'))
should look like this
array(':blocks' => Url::fromRoute('block.admin_display)->toString()))
Data model changes
(TBD)
Original report by [username]
Origins of the issue can be found in #2730625: hook_help API example contains a deprecated call to Drupal::url() and @tduong, commenting on patch by @ifrik #2702561-22: Provide a hook_help text.
| Comment | File | Size | Author |
|---|---|---|---|
| #36 | 2731817-36.drupal.Replace-all-calls-to-the-deprecated-Drupalurl-function-in-Core.patch | 425.21 KB | mikelutz |
| #30 | interdiff.2731817.27-30.txt | 761 bytes | mikelutz |
Comments
Comment #2
dbt102 commentedComment #3
Sonal.Sangale commentedComment #4
Sonal.Sangale commentedHi dbt102,
There are 483 depricated functions in drupal core.
Do we need to replace all these functions?
Comment #5
dbt102 commentedHi Sonal.Sangale,
I see what you mean. I just did a 'git pull' and searched the path drupal/core/modules and I come up with 464 occurances. At drupal/ root I find 481 occurances. So, I guess the exact number will fluctuate a bit depending on the most recent core commits.
I'm wondering about how/why 164 calls to Drupal::url() reports the number that it does?
Comment #6
jhodgdonWell, sometimes api.drupal.org may not have the right count... But anyway, this issue is about replacing the calls to Drupal::url(), not other deprecated functions. And this issue should be marked as Active until there is a patch (see links under the Priority and Status fields for definitions). Thanks!
Comment #7
Sonal.Sangale commentedReplaced the deprecated function from all core files.
Comment #9
jhodgdonTest fail is due to:
PHP Parse error: syntax error, unexpected ',' in ./core/modules/field_ui/src/Tests/ManageDisplayTest.php on line 407
Comment #10
ashishdalviHi jhodgdon,
Line 407 had incorrect implementation was Url::fromRoute(). Fixed it.
Thanks,
Comment #12
jhodgdonOK, no PHP syntax errors, but the remaining test failures look like real problems.
Comment #19
andypostthis replacement needs script to sed that, but using static analysis should also mention about usage in non-static class methods to follow-up with injection if required
Comment #20
andypostComment #21
mikelutzTrying a fresh S&R against 8.8 codebase.
Comment #22
mikelutzFix for some places where we were collecting metadata.
Comment #23
krzysztof domańskiComment #24
mikelutzFixing more issue where the S&R put the ->toString() in the wrong spot.
Comment #25
mikelutzComment #26
mikelutzHopefully this covers the rest of the failures..
Comment #27
mikelutzAnd adding the trigger error and resetting the actual test for \Drupal::url, and marking it legacy.
Comment #30
mikelutzgah, okay, one more. At least the test is finishing..
Comment #31
martin107 commentedSat down with a coffee this morning and visually scanned the patch
All seems ok
a) I think the appropriate pattern has been used. ->toSting() where need and otherwise where not.
b) No extraneous changes.
For what it is worth, I agree with the drive behind this issue.
It is good to see so many cases of the form \Drupal:??() removed.
Comment #32
andypostI bet it needs follow up to clean toString() half of places routes could be used as URL object or render type
Comment #33
simeApplied cleanly and looks consistent throughout.
Comment #34
mikelutzProbably, but for the purposes of this issue, I was not trying to change the typing. It was a string before, it's a string now., I think for the purposes of deprecation removal the direct replacement is best for a big patch like this.
Comment #35
mikelutzRe-rolling
Comment #36
mikelutzRe-rolling
Comment #37
roderikFWIW: I agree with doing just a straight replacement by toString() in this issue.
It's very well possible that there needs to be a followup issue to handle toString() cases better, but I have the feeling that there are a lot more toString() usages in Core which need to be reviewed anyway. I've just enumerated places where I've seen toString() being used without the cacheability metadata being properly handled, in #2735575-66: Make Url::toString(TRUE) explicit by having a Url::generate() method, as well as having GeneratedUrl::toString.
(And I'm OK with creating a followup issue if I need to... after I get some idea of whether my approach to #2735575 makes sense.)
Comment #38
andypostComment #39
catchCommitted/pushed to 8.8.x and cherry-picked to 8.7.x, thanks!
Comment #42
xjmSweet, great to see this in!
Comment #44
quietone commentedClosed #2699545: Replace \Drupal::l with Link::fromTextAndUrl in Link module as a duplicate of this one.