Issue Epic New Orphaned

#108986Improve MM handling in TYPO3 Core related to language + workspace concepts

Benni Mack 02/15/26, 17:16 updated 04/21/26, 11:30

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