Json Api : Translation lost when loading revision with the resourceRevision parameter

Created on 11 October 2022, over 1 year ago
Updated 24 April 2024, about 2 months ago

Problem/Motivation

When a request is sent to json API, the language prefix in the url allow currently to get the translation of a resource.

For example, a request to /fr/jsonapi/media/image/e5bf48ba-81d5-4caf-91df-a2c0a8563440/field_media_image will allow to get the field field_media_image value for the french version of the media.

However, if a resourceVersion parameter is added to the url, the specified version will be loaded but the translation will be lost.

For example, a request to /fr/jsonapi/media/image/e5bf48ba-81d5-4caf-91df-a2c0a8563440/field_media_image?resourceVersion=id:2 will provide the field field_media_image value for the revision 2 of the media but in the original language.

Steps to reproduce

  1. Install Drupal 9.4.8 with the standard profile
  2. Log as admin
  3. Enable Media, Content Translation and JSON:API
  4. Add a second language from /admin/config/regional/language (for example : French)
  5. Go to /admin/config/regional/content-language and enable translation for the Image media and its field_media_image field
  6. Create a new Image media from /media/add/image in the English language
  7. Translate the media into the language you added and specify another image in the field_media_image field
  8. Retrieve the uuid and the vid of your media from the media table in the database
  9. Go to /{langcode}/jsonapi/media/image/{uuid}/field_media_image (replace {langcode} by the langcode of the language you added in step 3 and {uuid} by the uuid of your media
  10. See that the json result contains correctly the image you put in the second language of the media
  11. Go then to /{langcode}/jsonapi/media/image/{uuid}/field_media_image?resourceVersion=id:{vid} (replace {vid} by the by the revision id of your media
  12. See that the json result contains the image of the original language instead of the one you specified in the {langcode} parameter

Proposed resolution

A solution could be to modify the ResourceVersionRouteEnhancer.php with a new condition to check if the resource is a content one and then load the right translation in this case (pulling it from the original entity).

🐛 Bug report
Status

Needs work

Version

11.0 🔥

Component
JSON API 

Last updated 1 day ago

Created by

🇦🇺Australia Nixou Sydney

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.

Production build 0.69.0 2024