Sub-issue of #2339219: [meta] Finalize URL generation API (naming, docs, deprecation)

Problem/Motivation

Most uses of l() and url() should be converted to supported alternatives in #2340251: Remove most remaining url() calls and #2343651: Remove most remaining l() calls. However, we need to ensure that module developers know that the procedural functions are deprecated before releasing a beta.

Proposed resolution

If any uses of l() or url() remain by the beta deadline date (Sept. 28):

  • Convert what uses we can.
  • Rename l() to _l() and mark it deprecated
  • Rename url() to _url() and mark it deprecated.
  • Clearly document both in the docblocks and the change record what l() and url() should be replaced with in all Drupal 7 usecases, including:
    • An internal path that matches an existing route, in procedural and class code.
    • An external URL.
    • Code that can accept either an internal or external URL.
    • Providing an URL to a "internal" (relative/absolute) url but not controlled by the Drupal routing system. (Edgecase, probably can just be converted to generateFromPath() which might be changed later but is not beta-blocking).

Remaining tasks

TBD

User interface changes

None.

API changes

l() and url() are deprecated and should no longer be used.

Postponed until

#2340251: Remove most remaining url() calls
#2343651: Remove most remaining l() calls

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

xjm’s picture

Issue summary: View changes
xjm’s picture

Issue tags: +beta blocker
xjm’s picture

Issue summary: View changes
catch’s picture

MustangGB’s picture

Status: Postponed » Active

Blockers are fixed, not sure why this is still postponed.

catch’s picture

#2343759: Provide an API function to replace url()/l() for external urls and others aren't fixed yet, there's no way to do the documentation part of this.

tim.plunkett’s picture

FileSize
138.4 KB

This is a simple rename that will apply on top of #2343759: Provide an API function to replace url()/l() for external urls.
Not marking needs review until then.

The docs replacements are really indicative of stale docs that really are talking about link or url generator.

larowlan’s picture

Can we get a combined patch (here or on a patch testing issue) to see if this is green on top of #2343759: Provide an API function to replace url()/l() for external urls ?

  1. +++ b/core/includes/common.inc
    @@ -640,7 +640,7 @@ function _format_date_callback(array $matches = NULL, $new_langcode = NULL) {
    +function _url($path = NULL, array $options = array()) {
    
    @@ -730,10 +730,10 @@ function drupal_http_header_attributes(array $attributes = array()) {
    +function _l($text, $path, array $options = array()) {
    

    Should we be adding @deprecated and 'documenting replacements' as per issue title?

  2. +++ b/core/lib/Drupal/Core/Asset/CssOptimizer.php
    @@ -138,10 +138,10 @@ protected function loadNestedFile($matches) {
    +    // Alter all internal _url() paths. Leave external paths alone. We don't need
    
    +++ b/core/lib/Drupal/Core/Routing/UrlGeneratorInterface.php
    @@ -67,10 +67,10 @@
    +   *     generated. Only set if _url() is invoked by Drupal\Core\Entity\Entity::uri().
    
    +++ b/core/modules/filter/src/Tests/FilterDefaultConfigTest.php
    @@ -21,7 +21,7 @@ class FilterDefaultConfigTest extends DrupalUnitTestBase {
    +    // Drupal\filter\FilterPermissions::permissions() calls into _url() to output
    

    >80

larowlan’s picture

FileSize
2.87 KB
140.54 KB

stab at docs, patch is against #2343759: Provide an API function to replace url()/l() for external urls
interdiff is against #7

larowlan’s picture

FileSize
563 bytes
140.54 KB

minor change

larowlan’s picture

Status: Active » Needs review
FileSize
196.41 KB

here's the patch at #10 plus the patch at #2343759: Provide an API function to replace url()/l() for external urls for a test-bot run.

effulgentsia’s picture

Status: Needs review » Reviewed & tested by the community

Looks great to me. Just one nit:

+++ b/core/includes/common.inc
@@ -730,10 +745,27 @@ function drupal_http_header_attributes(array $attributes = array()) {
+ * $external_link = \Drupal::linkGenerator()->generate($external_link);

Perhaps the above can be fixed on commit or if this gets rerolled.

The last submitted patch, 7: 2343661-rename-7.patch, failed testing.

larowlan’s picture

tim.plunkett’s picture

FileSize
140.54 KB

The do not test patch from #14, just in case someone is nervous about the bot.

alexpott’s picture

Status: Reviewed & tested by the community » Needs review
alexpott’s picture

FileSize
140.54 KB

Come on bot

alexpott’s picture

Status: Needs review » Reviewed & tested by the community

Thanks testbot

alexpott’s picture

Status: Reviewed & tested by the community » Fixed

Committed 002ae71 and pushed to 8.0.x. Thanks!

diff --git a/core/includes/common.inc b/core/includes/common.inc
index 7afd179..81c61b3 100644
--- a/core/includes/common.inc
+++ b/core/includes/common.inc
@@ -646,9 +646,9 @@ function _format_date_callback(array $matches = NULL, $new_langcode = NULL) {
  *   Use \Drupal\Core\Url::fromRoute() for internal paths served by Drupal
  *   controllers or \Drupal\Core\Url::fromUri() for external paths or
  *   non-controller or sub-domain URIs such as core/install.php. Note that
- *   \Drupal\Core\Url::fromUri() expects a valid URI including the scheme - In
- *   the case of URIs from the same sub-domain that are not handled by Drupal
- *   controllers, prepend base:://. For example:
+ *   \Drupal\Core\Url::fromUri() expects a valid URI including the scheme. URIs
+ *   from the same sub-domain that are not handled by Drupal controllers should
+ *   be prepended with base://. For example:
  * @code
  * $installer_url = \Drupal\Core\Url::fromUri('base://core/install.php')->toString();
  * $external_url = \Drupal\Core\Url::fromUri('http://example.com', ['query' => ['foo' => 'bar']])->toString();
@@ -753,9 +753,9 @@ function drupal_http_header_attributes(array $attributes = array()) {
  *   served by Drupal controllers use \Drupal\Core\Url::fromRoute(). For
  *   external paths or non-controller or sub-domain URIs such as
  *   core/install.php use \Drupal\Core\Url::fromUri(). Note that
- *   \Drupal\Core\Url::fromUri() expects a valid URI including the scheme - In
- *   the case of URIs from the same sub-domain that are not handled by Drupal
- *   controllers, prepend base:://. For example:
+ *   \Drupal\Core\Url::fromUri() expects a valid URI including the scheme. URIs
+ *   from the same sub-domain that are not handled by Drupal controllers should
+ *   be prepended with base://. For example:
  * @code
  * $installer_url = \Drupal\Core\Url::fromUri('base://core/install.php')->toString();
  * $installer_link = \Drupal::linkGenerator()->generate($installer_url);

Minor docs fixed on commit

webchick’s picture

DANCE DANCE DANCE!! :D

JohnAlbin’s picture

WOOT!

  • alexpott committed 002ae71 on 8.0.x
    Issue #2343661 by larowlan, tim.plunkett | xjm: Rename l() to _l() and...
effulgentsia’s picture

Status: Fixed » Needs review
FileSize
1.57 KB

Oops. When I reviewed earlier, I missed that our _l() docs additions were also failing to pass the $text parameter in the example code.

I'm also unclear why we're telling people to call \Drupal::linkGenerator()->generate() when none of core does that, and lots of places in core call the shorter \Drupal::l() instead, so this changes the doc to match what core actually does.

So, can we get this docs fix in before the beta gets tagged? While this isn't actually critical or beta blocking, I'm leaving the issue attributes alone, to get this in front of a committer prior to beta.

xjm’s picture

Also see #2347831: Fix documentation for \Drupal::url(), \Drupal::l(), etc. (and fix the change record).

Maybe we could merge those cleanups in there and set this back to fixed?

effulgentsia’s picture

Status: Needs review » Fixed
jhodgdon’s picture

Status: Fixed » Needs work

The change notice attached to this issue says that l() and url() deprecated. But they are actually gone. The change notice does not say they are removed or renamed. Please fix ASAP!

xjm’s picture

Status: Needs work » Fixed

I changed the word "deprecated" to "removed" in the CR title.... it already says:

The renamed _url() and _l() are deprecated and *will* be removed before 8.0.0 is released.

Status: Fixed » Closed (fixed)

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