ImageStyle::buildUrl() should generate root-relative URLs instead of absolute

Created on 8 March 2017, over 7 years ago
Updated 16 February 2023, over 1 year ago

Problem/Motivation

As for CSS and JS files, image style files should be referenced with root-relative paths by default. ImageStyle::buildUrl() returns absolute URLs. See #1494670: References to CSS, JS, and similar files should be root-relative URLs: avoids mixed content warnings & fewer bytes to send β†’ .

Proposed resolution

Return root-relative paths/URLs from ImageStyle::buildUrl().

An alternative approach is to update the documentation of ImageStyleInterface::buildUrl() to make it clearer that file_url_transform_relative() must be called on the result of buildUrl(), just as with file_create_url().

Remaining tasks

Needs tests. Needs discussion.

API changes

This is a proposed API change, but it should have limited impact. The buildUrl method is mentioned in a few issues, e.g. ✨ Twig image style filter/function Needs work . It is used in the video_embed_wysiwyg contrib module, and perhaps others. It is unlikely to be a breaking change in the majority of cases. For example, static_server.module would not be affected.

πŸ› Bug report
Status

Closed: outdated

Version

10.1 ✨

Component
Image systemΒ  β†’

Last updated about 11 hours ago

Created by

πŸ‡ΊπŸ‡ΈUnited States tedfordgif

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

    The change is currently missing an automated test that fails when run with the original code, and succeeds when the bug has been fixed.

Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • πŸ‡ΊπŸ‡ΈUnited States smustgrave

    This issue is being reviewed by the kind folks in Slack, #needs-review-queue-initiative. We are working to keep the size of Needs Review queue [2700+ issues] to around 400 (1 month or less), following Review a patch or merge request β†’ as a guide.

    As a bug will need tests before review.

  • πŸ‡ΊπŸ‡ΈUnited States tedfordgif

    As the original reporter of the issue, I think it's time to close this. Frankly the title contradicts itself, a root-relative URL isn't a URL. As Berdir pointed out, there have been related issues reported, some merged, which I'm now linking to this issue. Although we could convert this to a simple documentation update (my proposed alternate approach, patch attached for posterity), one might argue that the buildUrl() docs have always linked to the relevant methods for converting to root-relative links, so even this documentation patch is not really needed. Thanks to everyone for their contributions, but let's help clean up the issue queue by closing this.

  • Status changed to Closed: outdated over 1 year ago
  • πŸ‡ΊπŸ‡ΈUnited States tedfordgif
Production build 0.71.5 2024