Unable to use an image style for the image attribute

Created on 2 June 2023, over 1 year ago

Problem/Motivation

The ability to to use an image style for the image attribute for feed items.

Steps to reproduce

Prerequisites:
You need a content type with an image field.
You need an image style configured.

Steps to reproduce:
Create a JSON Feed view display.
Add a "field_media_image: Media" relationship.
Add an "Image" (category Media) field assigning a "field_media_image: Media" relationship
Set Formatter to "URL to image"
Set Image style to anything other than "None (original image)"

Under "Format" > "show" "Settings" assign the image attribute to the field you configured above.

Look at the view preview.
The image: value will be something similar to this:
"https:\/\/example.com\/sites\/default\/files\/styles\/thumbnail\/public?itok=Se38kw_N"
As you can see the path to the image style is correct but the image file name is cut off. If the image field (in the content type) is configured to use sub-directories, they will be missing from above.

Proposed resolution

Refactor the protected function getAbsoluteUrlForField to support image styles

Remaining tasks

User interface changes

none

API changes

none

Unreleated?

The protected function getAbsoluteUrlForField appears to return the base url for attributes that aren't set under Format show settings.
For example I have banner image attribute set to "- None - " (the default) but in the view preview "banner_image" has the value of: https:\/\/example.com\/

πŸ› Bug report
Status

Active

Version

2.0

Component

Code

Created by

πŸ‡ΊπŸ‡ΈUnited States jhuebsch

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

  • Issue created by @jhuebsch
  • πŸ‡ΊπŸ‡ΈUnited States jhuebsch
  • πŸ‡ΊπŸ‡ΈUnited States mcoughli

    Following up on this. We've identified the following in getAbsoluteUrlForField as our culprit:

    return Url::fromUserInput($field_value)->setAbsolute()->toString();
    

    Is there a reason the return value cannot simply be $field_value? When that string is passed to Url::fromUserInput the object returned doesn't seem to include the original URI anymore, rather a new object created using the route for the image style with no reference to even the relevant filename.

Production build 0.71.5 2024