Canvas editor loads and saves the site default translation instead of the entity's source translation
Overview
Since #3592033 (closed) a Canvas page's source language can differ from the site default language. The editor still assumes they are the same:
- Editor requests carry no language, so core upcasts the page to the site default translation. When the page has a translation in that language, the editor loads it instead of the source translation, and edits are saved to it. Discarding changes also targets that translation.
handleLanguageChange()inLanguageSelect.tsxchecksisDefault, so selecting the source language opens a read-only preview.
Steps to reproduce
- Site default
en,nlenabled. - Create a new Canvas page and switch its language to
nlbefore publishing (#3592033 (closed)). Add a component and publish. - Add an
entranslation with different component inputs. - Open
/canvas/editor/canvas_page/N. The editor loads theentranslation instead of thenlsource, and edits are saved to theentranslation./nl/canvas/editor/...redirects back to the prefix-free URL.
Proposed resolution
- Add a route enhancer for the routes through which the editor reads or writes the page: layout GET/POST/PATCH, the component instance and page data forms, auto-save discard and auto-save status. When the request selects no language, it replaces the upcast page with its source translation. A language selected by URL prefix, domain, session or
canvas_preview_langcodeis still used. Route enhancers run before access checks, so access is checked on the edited translation. - Build the entity forms for the translation passed in.
ContentEntityFormotherwise picks the translation in the negotiated language. LanguageSelect.tsx: compare againsttranslations.available[0]instead ofisDefault.
The content API and JSON:API are unchanged: the URL still selects the language. Rendering the editor in the source language's context is #3546597.
Related
Split out of #3591976 (closed). Supersedes !1590 (closed), which redirected only the layout GET; writes then targeted a different translation (409).
Edited by Fons Vandamme