Attempted to patch an order entity in Commerce and received an exception. The \Drupal\jsonapi\ParamConverter\EntityUuidConverter::convert fails due to the default language being und.
URL https://commerce2x-api.ddev.local/jsonapi/commerce_order/physical/667805...
{
"jsonapi": {
"version": "1.0",
"meta": {
"links": {
"self": {
"href": "http://jsonapi.org/format/1.0/"
}
}
}
},
"errors": [
{
"title": "Method Not Allowed",
"status": "405",
"detail": "The requested translation of the resource object does not exist, instead modify one of the translations that do exist: und.",
"links": {
"via": {
"href": "https://commerce2x-api.ddev.local/jsonapi/commerce_order/physical/667805a1-eb4d-4c3b-a821-2f135be4f5d4"
},
"info": {
"href": "http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html#sec10.4.6"
}
}
}
]
}
The problem:
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));
}
The order's language is und but the current language is en.
The entire logic around if (in_array($method, ['PATCH', 'DELETE'], TRUE)) { should be ignored if the language for the entity is und.
| Comment | File | Size | Author |
|---|---|---|---|
| #3 | 3067405-3.patch | 1.24 KB | mglaman |
Comments
Comment #2
mglamanThis conditional update fixed it, to ensure the entity is translatable:
Comment #3
mglamanHere is a patch to see if this breaks anything. Allowed me to PATCH an order.
Comment #5
cspitzlayIsn't that a duplicate of #3043168: PATCH 405 for untranslatable content entities with different default language than English?
Comment #6
mglamanYes, yes it is.