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.

Comments

dbt102 created an issue. See original summary.

dbt102’s picture

Issue summary: View changes
Sonal.Sangale’s picture

Assigned: Unassigned » Sonal.Sangale
Sonal.Sangale’s picture

Hi dbt102,

There are 483 depricated functions in drupal core.

Do we need to replace all these functions?

dbt102’s picture

Hi 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?

jhodgdon’s picture

Title: Replace all 164 calls to the deprecated Drupal::url() function in Core. » Replace all calls to the deprecated Drupal::url() function in Core
Status: Needs work » Active

Well, 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!

Sonal.Sangale’s picture

Status: Active » Needs review
StatusFileSize
new416.62 KB

Replaced the deprecated function from all core files.

Status: Needs review » Needs work

The last submitted patch, 7: 2731817-6.patch, failed testing.

jhodgdon’s picture

Test fail is due to:

PHP Parse error: syntax error, unexpected ',' in ./core/modules/field_ui/src/Tests/ManageDisplayTest.php on line 407

ashishdalvi’s picture

Status: Needs work » Needs review
StatusFileSize
new416.64 KB
new898 bytes

Hi jhodgdon,

Line 407 had incorrect implementation was Url::fromRoute(). Fixed it.

Thanks,

Status: Needs review » Needs work

The last submitted patch, 10: 2731817-10.patch, failed testing.

jhodgdon’s picture

OK, no PHP syntax errors, but the remaining test failures look like real problems.

Version: 8.2.x-dev » 8.3.x-dev

Drupal 8.2.0-beta1 was released on August 3, 2016, which means new developments and disruptive changes should now be targeted against the 8.3.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.3.x-dev » 8.4.x-dev

Drupal 8.3.0-alpha1 will be released the week of January 30, 2017, which means new developments and disruptive changes should now be targeted against the 8.4.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.4.x-dev » 8.5.x-dev

Drupal 8.4.0-alpha1 will be released the week of July 31, 2017, which means new developments and disruptive changes should now be targeted against the 8.5.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.5.x-dev » 8.6.x-dev

Drupal 8.5.0-alpha1 will be released the week of January 17, 2018, which means new developments and disruptive changes should now be targeted against the 8.6.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.6.x-dev » 8.7.x-dev

Drupal 8.6.0-alpha1 will be released the week of July 16, 2018, which means new developments and disruptive changes should now be targeted against the 8.7.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.7.x-dev » 8.8.x-dev

Drupal 8.7.0-alpha1 will be released the week of March 11, 2019, which means new developments and disruptive changes should now be targeted against the 8.8.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

andypost’s picture

this 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

andypost’s picture

Issue tags: +@deprecated
mikelutz’s picture

Assigned: Sonal.Sangale » Unassigned
Status: Needs work » Needs review
StatusFileSize
new424.25 KB

Trying a fresh S&R against 8.8 codebase.

mikelutz’s picture

Fix for some places where we were collecting metadata.

krzysztof domański’s picture

mikelutz’s picture

Fixing more issue where the S&R put the ->toString() in the wrong spot.

mikelutz’s picture

Issue summary: View changes
mikelutz’s picture

Component: documentation » base system
Category: Plan » Task
Issue tags: +Drupal 9
StatusFileSize
new424.29 KB
new2.99 KB

Hopefully this covers the rest of the failures..

mikelutz’s picture

And adding the trigger error and resetting the actual test for \Drupal::url, and marking it legacy.

Status: Needs review » Needs work
mikelutz’s picture

Status: Needs work » Needs review
StatusFileSize
new425.08 KB
new761 bytes

gah, okay, one more. At least the test is finishing..

martin107’s picture

Status: Needs review » Reviewed & tested by the community

Sat 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.

andypost’s picture

I bet it needs follow up to clean toString() half of places routes could be used as URL object or render type

sime’s picture

Applied cleanly and looks consistent throughout.

mikelutz’s picture

I bet it needs follow up to clean toString() half of places routes could be used as URL object or render type

Probably, 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.

mikelutz’s picture

mikelutz’s picture

roderik’s picture

FWIW: 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.)

catch’s picture

Version: 8.8.x-dev » 8.7.x-dev
Status: Reviewed & tested by the community » Fixed

Committed/pushed to 8.8.x and cherry-picked to 8.7.x, thanks!

  • catch committed 9791614 on 8.8.x
    Issue #2731817 by mikelutz, ashishdalvi, Sonal.Sangale, dbt102, andypost...

  • catch committed 84e5d23 on 8.7.x
    Issue #2731817 by mikelutz, ashishdalvi, Sonal.Sangale, dbt102, andypost...
xjm’s picture

Sweet, great to see this in!

Status: Fixed » Closed (fixed)

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

quietone’s picture