Problem/Motivation
Individual and collection reads validate the language selector through one shared resolver: an unconfigured langCode is rejected with 422 and a detail naming the language.
The /related/ endpoint (GET .../{uuid}/{relationship-field}) reads the query parameter raw and never validates it, so the same typo gets a different and misleading answer depending on the relationship's cardinality:
- a to-one relationship returns
404("The ... translation of the specified resource does not exist"), indistinguishable from a genuinely missing translation of a configured language; - a to-many relationship returns
200with every target moved intometa.omitted, reported as a language miss.
Both answers tell the client the content is missing, when the truth is that the request named a language the site does not have. One contract, one error model: identical mistakes should produce identical status codes and details on every read surface.
Steps to reproduce
- Site with
en(default) andfrconfigured, and an article with an entity-reference relationship. GET /jsonapi/node/article/{uuid}?langCode=es(unconfigured) →422, "The specified language ("es") is invalid or has not been configured."GET /jsonapi/node/article/{uuid}/{to-one-relationship}?langCode=es→404.GET /jsonapi/node/article/{uuid}/{to-many-relationship}?langCode=es→200, with every target undermeta.omitted.
Proposed resolution
Resolve the selector once at the top of getRelated() through the shared resolver (getResourceLanguage()) instead of reading the query parameter raw, and take the langcode from the resolved language. The resolver is memoized per request and already runs on the two sibling endpoints, so this adds no query and changes nothing for well-formed requests. Everything downstream keeps consuming the same value.
The error detail is not re-authored: the test references the same literal the individual endpoint's assertion uses, so the two strings cannot drift apart. Clients match on them.
Two notes on scope, because an earlier draft of this issue proposed more:
- No header guards are added. Language request headers are deliberately inert on reads since #3613823, and
Content-Languagewas retired as a write selector in #3614200. Routing through the shared resolver does not reintroduce a header rejection here: the resolver'sContent-Languagerejection is gated on the request not being cacheable, so it applies to writes only. - Genuinely missing translations of configured languages keep their current behavior: a to-one strict miss stays a
404advertising the target's available translations, and to-many targets stay excluded and reported undermeta.omitted.
A side effect worth having: the resolver throws a CacheableUnprocessableEntityHttpException carrying the config:configurable_language_list cache tag, so the related endpoint's rejection is now cacheable and self-invalidating when the language is later added, matching its sibling endpoints.
Issue fork jsonapi_multilingual-3614384
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #4
lauriii