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.
Part of #2339219: [meta] Finalize URL generation API (naming, docs, deprecation).
Problem/Motivation
The change record says:
"\Drupal::url() *may* also become deprecated and *may* be removed. New code should use the Url class directly...
That was from the original change record draft. However, for the beta release, either it's deprecated, or it's not and we will keep it in D8.
Proposed resolution
- Retain
\Drupal::url()
as a convenience wrapper for Url::toString(). - Update the documentation to refer to Url.
- Remove the paragraph from the change record.
Remaining tasks
At some point we may wish to change it to use Url
internally instead so that we don't have so many different code paths.
User interface changes
N/A
API changes
None.
Comment | File | Size | Author |
---|---|---|---|
#7 | interdiff.txt | 1.93 KB | effulgentsia |
#7 | url-l-docs-2347831-7.patch | 9.27 KB | effulgentsia |
#4 | url-docs-2347831.patch | 8.23 KB | xjm |
Comments
Comment #1
larowlanLooks very familiar
Comment #2
xjmDiscussed with @larowlan, @tim.plunkett, and @alexpott. We decided to leave
\Drupal::url()
in as a convenience wrapper fornew Url(..)->toString()
(which means we are keeping it in 8.x.x) and just update the docs to reference Url.Comment #3
xjmNot a beta blocker then either, though I would encourage us to commit it before beta anyway as it will only be docs. Working on it now.
Comment #4
xjmThe
\Drupal::l()
docs were also wrong now, so adding that to scope. This is what I have for now. Time to sleep.Comment #5
xjmComment #6
larowlanwhy remove this hunk?
Comment #7
effulgentsia CreditAttribution: effulgentsia commentedReverted #6 and merged #2343661-23: Rename l() to _l() and url() to _url(), and document replacements.
Comment #8
Gábor HojtsyLooks great! Thanks for clearing it up.
Comment #9
alexpottCommitted 64de978 and pushed to 8.0.x. Thanks!
Comment #11
xjm#6 was because we went back and forth about it and didn't actually come to a consensus as to whether we should recommend using
Url::fromRoute()
overnew Url()
generally, but not a big deal either way. Thanks everyone!Comment #13
donquixote CreditAttribution: donquixote commentedI don't understand why @param and @return docs were removed from \Drupal::url() and \Drupal::l().
These docs are meant at least 50% for the machine (the IDE, mostly), which can't do anything with the "See \Drupal\Core\Url::fromRoute() for detailed documentation."
The proposed changes in #2363523: Docblock / cleanup in \Drupal will re-introduce the @param and @return, albeit with only a short description, and the "for detailed documentation, see ..." still in place.
The other question is, for url(), why do we refer to \Drupal\Core\Url::fromRoute(), and not to \Drupal\Core\Routing\UrlGeneratorInterface::generateFromRoute(), which is the actual function being called?
More discussion over there, I would say.