Problem/Motivation
When exporting content using a Views REST Export, images do not always honor the display settings configured in the content type. Specifically:
- If the View format is set to Entity, the image field outputs the original image URL, not the image style (e.g., medium, thumbnail) configured in the content type’s Manage Display settings. There is no option to change this behavior.
- If the View format is set to Fields, it is possible to choose a specific image style, but:
- There is no "Default" image style option that would follow the content type's display configuration.
- Important image metadata (e.g.,
alt
,title
,width
,height
) is not included in the output, making it difficult for frontend consumers (like SPAs or mobile apps) to render the image accessibly and accurately.
This limits flexibility, leads to inconsistency, and reduces accessibility of API-based frontends relying on the exported data.
Steps to reproduce
- Create a content type (
basic_page
) with an image field. - Set the image field to use a specific image style (e.g., Medium) in Manage Display.
- Create a View with a REST Export display.
- Set the View format to:
- Entity: Note that the image field outputs the original image URL, ignoring the display settings.
- Fields: Add the image field and choose an image style. No option is available to use the “default” (Manage Display) style. Also,
alt
,title
,width
,height
values are not exposed.
Proposed resolution
- Enhance the Entity row plugin in Views REST Export to respect the image style set in the content type's Manage Display.
- When using Fields format:
- Provide a "Default" image style option that reflects the display configuration of the content type.
- Extend the image field formatter or Views integration to include image metadata (alt, title, width, height) in the export.
These changes will maintain consistency across rendered and exported content and improve API accessibility.
Remaining tasks
- Technical analysis to determine how image styles are selected in the Entity row plugin.
- Implement logic to default to display settings.
- Update image field output to include metadata.
- Write functional tests covering both Field and Entity format output.
- Update documentation for REST Views and image field behavior.
User interface changes
- Addition of a "Default" image style option in Views UI for image fields.
- Possibly new checkboxes or fields to select which image metadata to include.
Introduced terminology
API changes
Data model changes
Release notes snippet
Original report by RobKoberg
I have added an image field to a basic_page content type and set the display to use the medium image style.
When using a views rest export:
- With the format set to show as an entity, the original file URL is used rather than that set in the display settings and there is no way to set the appropriate image style. It should use the image style set in the display settings.
- With the format set to show as fields, I can select the same image style I used in the content type's display settings. There should be a "default" option that does this (uses the content type's display setting) in case it changes without the views knowledge. In addition, there is no way to get other information like alt, title, width, height, etc.