REST views (json) should output absolute image URLs

Created on 25 September 2017, almost 7 years ago
Updated 18 December 2023, 6 months ago

When we create views REST Exports (json) to be consumed by external systems the src URLs of images inside text fields are relative (i.e. src="/sites/all/...) and the images get broken. Therefore the consuming systems will need to preprocess the SRCs inside text fields which it involves regular expression replacement. There is no easy way to do this within drupal other than actually creating a serializer module as described in https://www.drupal.org/node/2754515 β†’ .

The solution could be an option that asks for absolute/relative urls inside text fields
or a workaround would be to apply a filter to a text format and use that format all throughout the site if the contents are served to external systems by means of JSON. (i.e. https://www.drupal.org/project/rel_to_abs β†’ )

For more reason why this change is needed please look at similar issue and fix #88183: Relative URLs in feeds should be converted to absolute ones β†’

✨ Feature request
Status

Closed: works as designed

Version

8.2 ⚰️

Component
RESTΒ  β†’

Last updated about 1 month ago

Created by

πŸ‡¬πŸ‡·Greece GiorgosK Chios, Greece πŸ‡¬πŸ‡·

Live updates comments and jobs are added and updated live.
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.

  • πŸ‡­πŸ‡ΊHungary Szultino

    #24:
    If you want to convert rel to abs in fullhtml without use outer module, in views in the field settings choose "Override the output of this field with custom text", and write this kind of twig code:

    {{ field_FIELDNAME|replace({'"/files/': '"https://DOMIAN/files/'})|raw }}

    The "raw" command at the end makes some errors (for example with media output), but I'm searching the perfect solutions...

  • πŸ‡ΊπŸ‡ΈUnited States angrytoast Princeton, NJ

    Updating with a related issue link to a change that provides an "Use absolute link" option at the image URL field formatter level. This may be a viable solution?
    https://www.drupal.org/project/drupal/issues/3041402 ✨ Add option absolute url in formatter URL to image Needs review

  • πŸ‡ΊπŸ‡ΈUnited States angrytoast Princeton, NJ
Production build 0.69.0 2024