#108986Improve MM handling in TYPO3 Core related to language + workspace concepts
Description
I went through a lot of MM issues in TYPO3, and analyzed this – also talking to Olly Hader and Lolli to find a solution to bi-directional editing when reading and persisting relations. Here is my TLDR:
The problem
TYPO3’s MM tables store bare uid_local/uid_foreign pairs with no concept of language or workspace. When a record is translated, it gets a new uid. When versioned in a workspace, yet another uid. Every part of the system — DataHandler, RelationHandler, Extbase, FormEngine — must independently guess which uid to store in MM, and they guess differently. The result: 25+ interconnected bugs spanning 12 years, affecting bidirectional MM relations, l10n_mode=exclude, allowLanguageSynchronization, and workspaces.
The new principle
Add sys_language_uid and t3ver_wsid columns to all MM tables by default. MM rows always store the default-language live uid for both sides — never translated or workspace-versioned uids. The new columns provide context: sys_language_uid says which language version of the local-side record “owns” this relation set, and t3ver_wsid isolates workspace changes without the fragile UID-swap mechanism used today.
Rules for tables
Tables are either language-aware (LA — they have sys_language_uid, e.g. tt_content, pages, sys_category) or non-language-aware (NLA — no translation concept, e.g. be_groups, fe_groups). The local-side table’s capabilities determine MM behavior: if LA, each translation can have its own relations (unless l10n_mode=exclude shares them at sys_language_uid=0); if NLA, sys_language_uid is always 0 regardless of the foreign side. This covers all four combinations (LA->LA, LA->NLA, NLA->LA, NLA->NLA) with one simple rule: the foreign table’s language-awareness is irrelevant for MM storage — the overlay/display layer handles translating the foreign side. The same principle applies to workspace-awareness and t3ver_wsid.
Core write + read (DataHandler / general path)
On the write side, all item uids are normalized to default-language live uids before writing. sys_language_uid is set from the local record’s language (or 0 for NLA/l10n_mode=exclude), t3ver_wsid from the current workspace. Workspace publishing becomes a simple DELETE live rows + UPDATE ws→live on the column — no more UID-swapping via convertItemArray(). On the read side, RelationHandler::readMM() adds WHERE sys_language_uid = X AND t3ver_wsid IN (0, ws) filtering. For l10n_mode=exclude, the caller passes languageUid=0, so shared rows are read regardless of frontend language. Workspace overlay prefers workspace rows over live rows for the same uid pair.
Extbase (still separate for the time being)
Extbase has its own persistence layer that bypasses DataHandler — fixes to DataHandler alone don’t help Extbase. On the write side, Extbase’s persistence must also normalize uids and set the context columns, using the same rules. On the read side, Extbase has two MM paths: the SQL JOIN path in Typo3DbQueryParser (adds sys_language_uid and t3ver_wsid conditions to the JOIN, with a NOT EXISTS subquery for workspace overlay) and the DataMapper::fetchRelated() path (delegates to the same read logic). The current complexity in resolveParentId() — which branches on PROPERTY_VERSIONED_UID and PROPERTY_LOCALIZED_UID to guess the right uid — collapses to simply using getUid(), because MM now always stores default-language uids with context columns for disambiguation.
How it all plays out
- First add the new fields to the MM tables
- Adapt the RelationHandler (or use two classes now for reading and writing) to support handing in the languageId / workspaceId and use it everywhere in DataHandler, FormEngine and Frontend
- Adapt Extbase as well, build more tests to it
- Build a migration path or consider building an upgrade wizard
Reviews 3
Related issues 24
- Bug #62727Allow MM reference translation on non inline fields for bidirectional MM relations
- Bug #62921l10n_mode with relations does not work in Extbase
- Bug #65859Support l10n_mode in extbase
- Bug #76519Extbase not respecting l10n_mode = mergeIfNotBlank for mm relations
- Bug #82558The relation of MM table records are saved wrong for element translations in TYPO3 8.7.
- Bug #82657l10n_mode exclude ignored in repository
- Bug #84682TYPO3 8 Relationship Localization Bug
- Bug #88452TCA field type inline ignores l10n_mode "exclude"
- Bug #89768l10n_mode "exclude" does not work with inline type
- Bug #90430Language handling of bidirectional mm selects is not consitent.
- Bug #92777TCA l10n_mode exclude (as well as allow language syncronisation bahviour) and bidirectional MM relations cause Extbase to use uidLocalized instead of UID from foreign side
- Bug #93765Extbase loses language overlay for related records
- Feature #94539Documentation on how to work with 1:n and n:1 relations and translations
- Bug #100002Bidirectional "allowLanguageSynchronization" including "l10n_mode => exclude" not possible with a MM relation
- Bug #100816Translations for bidirectional relations are not output reliably.
- Epic #101557Translation Handling Findings
- Story #101561DataHandler related translation issues
- Story #101566Extbase related translation issues
- Bug #102336Add support for localizing n:1 relations
- Bug #105843Language fallback broken for objectstorages
- Bug #106483Exception 1546632293 Could not get value of property [model] make sure the property is either public or has a getter
- Bug #107078Bidirectional editing of records with multiple languages sets wrong uids in mm-table
- Bug #111474DataHandler: inline MM relations are lost when a record gets its workspace version
- Bug #111492Saving nested inline records in a workspace breaks the grandchild’s parent relation