Allow links to external routes to gather metadata in LinkGenerator::generate

Created on 25 July 2023, about 1 year ago
Updated 11 August 2023, about 1 year ago

Problem/Motivation

In 🌱 [Meta] Allow StreamWrapper's to provide cacheability metadata Active it was noted that propagation of cacheability information for external URLs is currently impossible because LinkGenerator::generate will not propagate it.

The code that exempts external URLs from cacheability information was removed in #2568977: Replace SafeMarkup::format() in the link generator - it's a bad example to everyone β†’ while removing the $collect_bubbleable_metadata argument and always returning an object with the information. However the code that is in URL::toString and the methods that it subsequently calls all seem to handle cacheability for external URLs just fine. They have different code-paths for unrouted/routed URLs but both of those paths allow collecting cacheability information.

Steps to reproduce

Proposed resolution

Update the code in the if ($url->isExternal()) to collect cacheability information and notice that it becomes the same as the default case, subsequently remove the if-branch and handle external URLs in the same way as other URLs.

Remaining tasks

User interface changes

API changes

Data model changes

Release notes snippet

✨ Feature request
Status

Needs work

Version

11.0 πŸ”₯

Component
RenderΒ  β†’

Last updated 2 days ago

Created by

πŸ‡³πŸ‡±Netherlands Kingdutch

Live updates comments and jobs are added and updated live.
  • Needs change record

    A change record needs to be drafted before an issue is committed. Note: Change records used to be called change notifications.

Sign in to follow issues

Comments & Activities

  • Issue created by @Kingdutch
  • Issue was unassigned.
  • Status changed to Needs review about 1 year ago
  • last update about 1 year ago
    29,881 pass
  • πŸ‡³πŸ‡±Netherlands Kingdutch

    Uploading a patch that makes the proposed change. Since in the LinkGeneratorTest we mock the assembler, we need to change it to return a GeneratedUrl instance, since external URLs are now tested with toString(TRUE) rather than toString(FALSE).

    We can see this is an API stable change because the actual output of the link itself is not changed (assuming no other tests break and need fixing).

  • πŸ‡ΊπŸ‡ΈUnited States mglaman WI, USA

    This seems to make sense, to me. The code had an explicit way to exit early if the link was external by directly creating a generated link. Now external links get generated the same as any others.

    I wouldn't expect any tests to be broken as this is very internal.

  • πŸ‡³πŸ‡±Netherlands Kingdutch
  • πŸ‡¨πŸ‡­Switzerland Berdir Switzerland

    I don't remember why exactly we had this special case, Not sure if there's a performance aspect to it.

    That said, this barely seem relevant to the meta issue because it is about Link objects, which are not used in StreamWrappers, only the underlying Url objects. I suppose it does become an issue if you use FileUrlGenerator::generateUrl() and then pass that Url to a Link object, but there are not that many cases in core that actually do this. It's the last piece in the puzzle.

  • πŸ‡¨πŸ‡­Switzerland Berdir Switzerland

    One more thing to consider here. We might want to deprecate getExternalUrl() only in D11 for D12 as we deprecate the separate interface. Modules that will want to remain compatible with D10 and D11 will need to keep the method anyway and that's going to be confusing otherwise.

  • Status changed to Needs work about 1 year ago
  • πŸ‡ΊπŸ‡ΈUnited States smustgrave

    Correct me if I'm wrong but this seems like a change that could use a CR?

Production build 0.71.5 2024