Quantcast
Channel: Issues for Drupal core
Viewing all articles
Browse latest Browse all 299219

PATCH is not allowed if entity translation doesn't already exist.

$
0
0

Problem/Motivation

In my case translating user entity field throws an error if it is not already translated. And of course the fields are not translated yet, because only the default English content exists after creating a user.

https://api.website.com/fi/jsonapi/user/user/c59cedc5-895d-41e6-a88c-504c5edb7278||14703||Symfony\Component\HttpKernel\Exception\MethodNotAllowedHttpException: The requested translation of the resource object does not exist, instead modify one of the translations that do exist: en, de. in Drupal\jsonapi\ParamConverter\EntityUuidConverter->convert() (line 72 of .../core/modules/jsonapi/src/ParamConverter/EntityUuidConverter.php).

Steps to reproduce

1. Enable three languages English /en, Finnish /fi, German /de. Leave the site default as English. /admin/config/regional/language
2. Create a custom field to the User entity: "Bio". /admin/config/people/accounts/fields
3. Enable user entity translation. /admin/config/regional/content-language
4. Set "Bio" field translateble. /admin/config/regional/content-language
5. Enable Create translations, Edit translations, Translate user permissions (not sure if all needed).
6. In the Drupal UI as admin: Translate any users "Bio" field in /de and leave /fi not translated. /de/user/123/translations/add/en/de
7A Send PATCH /jsonapi/user/user/123 to change "Bio" field. => WORKS!
7B Send PATCH /de/jsonapi/user/user/123 to change "Bio" field. => WORKS!
7C Send PATCH /fi/jsonapi/user/user/123 to change "Bio" field. => FAILS with an error shown above.

Proposed resolution

Allow adding a translation if the entity translation is allowed for that entity field and the language is enabled on the site.

Release notes snippet

The responsible code in jsonapi/src/ParamConverter/EntityUuid/Converter.php

          if ($method === 'PATCH'&& $entity->language()->getId() !== $current_content_language) {
            $available_translations = implode(', ', array_keys($entity->getTranslationLanguages())); 
            throw new MethodNotAllowedHttpException(['GET'], sprintf('The requested translation of the resource object does not exist, instead modify one of the translations that do exist: %s.', $available_translations));
          }

Viewing all articles
Browse latest Browse all 299219

Latest Images

Trending Articles



Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>