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. #2361299: Twig image style filter/function. 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.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

tedfordgif created an issue. See original summary.

tedfordgif’s picture

Patch for 8.2.x, will update to 8.4.x.

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.

dbjpanda’s picture

Status: Active » Needs work
Issue tags: +Needs reroll

Needs reroll for 8.6.x

error: patch failed: core/modules/image/src/Entity/ImageStyle.php:225
error: core/modules/image/src/Entity/ImageStyle.php: patch does not apply
error: patch failed: core/modules/image/src/Tests/ImageAdminStylesTest.php:359
error: core/modules/image/src/Tests/ImageAdminStylesTest.php: patch does not apply
error: patch failed: core/modules/image/src/Tests/ImageDimensionsTest.php:36
error: core/modules/image/src/Tests/ImageDimensionsTest.php: patch does not apply
error: patch failed: core/modules/image/src/Tests/ImageThemeFunctionTest.php:74
error: core/modules/image/src/Tests/ImageThemeFunctionTest.php: patch does not apply
error: patch failed: core/modules/responsive_image/src/Tests/ResponsiveImageFieldDisplayTest.php:317
error: core/modules/responsive_image/src/Tests/ResponsiveImageFieldDisplayTest.php: patch does not apply
yogeshmpawar’s picture

Assigned: Unassigned » yogeshmpawar
yogeshmpawar’s picture

Assigned: yogeshmpawar » Unassigned
Issue tags: -Needs reroll
FileSize
11.46 KB

Re-roll the patch against 8.6.x because its failed to apply.

yogeshmpawar’s picture

Status: Needs work » Needs review

Triggering test bots

Status: Needs review » Needs work

The last submitted patch, 7: 2858885-buildUrl_relative-7.patch, failed testing. View results

yogeshmpawar’s picture

Status: Needs work » Needs review
FileSize
11.46 KB
854 bytes

One thing missed, removed in updated patch with interdiff.

Status: Needs review » Needs work

The last submitted patch, 10: 2858885-buildUrl_relative-10.patch, failed testing. View results

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.

rogerpfaff’s picture

Status: Needs work » Needs review
FileSize
11.62 KB

I rerolled this patch against 8.7.x. Most things failed due to moved test files.

Status: Needs review » Needs work

The last submitted patch, 13: 2858885-buildUrl-relative-13.patch, failed testing. View results

rogerpfaff’s picture

rogerpfaff’s picture

rogerpfaff’s picture

Had to reroll it against latest 8.7.x and two more tests in rdf failed after changing everything.

Somehow I have the impression that this patch will break some things like in the linked issue because people will expect buildUrl() to return an absolute url. I have changed this in the interface comment to give a hint.

rogerpfaff’s picture

rogerpfaff’s picture

rogerpfaff’s picture

Status: Needs work » Needs review

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.

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

Drupal 8.8.0-alpha1 will be released the week of October 14th, 2019, which means new developments and disruptive changes should now be targeted against the 8.9.x-dev branch. (Any changes to 8.9.x will also be committed to 9.0.x in preparation for Drupal 9’s release, but some changes like significant feature additions will be deferred to 9.1.x.). For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

deepakrmali’s picture

This patch is Important to apply on core modules.
Even though we have valid SSL certification for application, but due to absolute image path url get generate without https. So because of this the application showing it is non secure..

deepakrmali’s picture

Path for Drupal version 8.9.x

The last submitted patch, 23: 2858885_buidUrl-relative-urls-20.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

Status: Needs review » Needs work

The last submitted patch, 24: 2858885_buidUrl-relative-urls-21.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

deepakrmali’s picture

Removed space & resolved failures test

Berdir’s picture

Version: 8.9.x-dev » 9.1.x-dev

Drupal 8.9.0-beta1 was released on March 20, 2020. 8.9.x is the final, long-term support (LTS) minor release of Drupal 8, which means new developments and disruptive changes should now be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 9.1.x-dev » 9.2.x-dev

Drupal 9.1.0-alpha1 will be released the week of October 19, 2020, which means new developments and disruptive changes should now be targeted for the 9.2.x-dev branch. For more information see the Drupal 9 minor version schedule and the Allowed changes during the Drupal 9 release cycle.

s.messaris’s picture

In case we want to get this in after all, and for anyone else needing this as I do, here is a patch that changes image style urls to relative, after applying the patch in 2669074.

Version: 9.2.x-dev » 9.3.x-dev

Drupal 9.2.0-alpha1 will be released the week of May 3, 2021, which means new developments and disruptive changes should now be targeted for the 9.3.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.0-rc1 was released on November 26, 2021, which means new developments and disruptive changes should now be targeted for the 9.4.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

basvredeling’s picture

Patch from #31 applies to Drupal 9.3 and is all you need, it seems.

markie’s picture

Status: Needs work » Needs review

setting to "needs review" so #31 can get tested

markie’s picture

Patch applies cleanly on 9.3 and works as described. Not sure why it doesn't apply on 9.4..

Berdir’s picture

That test run was against 9.2, not 9.4. I added a manual test against 9.4.

Version: 9.4.x-dev » 9.5.x-dev

Drupal 9.4.0-alpha1 was released on May 6, 2022, which means new developments and disruptive changes should now be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.5.x-dev » 10.1.x-dev

Drupal 9.5.0-beta2 and Drupal 10.0.0-beta2 were released on September 29, 2022, which means new developments and disruptive changes should now be targeted for the 10.1.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

smustgrave’s picture

Status: Needs review » Needs work
Issue tags: +Needs Review Queue Initiative, +Needs tests

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.

tedfordgif’s picture

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.

tedfordgif’s picture

Priority: Normal » Minor
Status: Needs work » Closed (outdated)