#103063Extbase repository does not respect fallback chain
Description
*Topic*
In a site with multiple languages and fallback chains configured, extbase models retrieved by an extbase repository do not respect the configured fallback chains.
Example
SiteConfig (only relevant parts):
languages:
-
title: 'English (Global)'
enabled: true
languageId: 0
base: /en/
-
title: ES-ES
enabled: true
base: /es-es/
typo3Language: es
fallbackType: strict
flag: es
languageId: 15
-
title: 'AR-ES'
enabled: true
base: /es-ar/
typo3Language: es
fallbackType: fallback
fallbacks: 15
languageId: 5
Extbase Models in DB:
uid, sys_language_uid, title, l10n_parent 1, 0, 'Model 1 global', 0 2, 15, 'Model 1 spanish', 1 3, 0, 'Model 2 global', 0 4, 5, 'Model 2 spanish argentina', 3 5, 15, 'Model 2 spanish', 3
Using a extbase repository $repository->findAll() return the following results:
1, 0, 'Model 1 global', 0 4, 5, 'Model 2 spanish argentina', 3
instead of the expected result:
2, 15, 'Model 1 spanish', 1 4, 5, 'Model 2 spanish argentina', 3
I’ve tracked the problem down to
\TYPO3\CMS\Extbase\Persistence\Generic\Storage\Typo3DbBackend->overlayLanguageAndWorkspaceForSingleRecord
in line 540 a new instance of LanguageAspect is created but without handing over the fallbackChain of the original languageAspect:
$customLanguageAspect = new LanguageAspect($languageUid, $languageUid, LanguageAspect::OVERLAYS_MIXED);
$row = $pageRepository->getLanguageOverlay($tableName, $row, $customLanguageAspect);
I am not sure, if this is done with purpose, but the pageRepository further more does not know about the configured fallbackChain and so cannot return the correct record. In my opinion the above code should look like this:
$customLanguageAspect = new LanguageAspect($languageUid, $languageUid, LanguageAspect::OVERLAYS_MIXED, $languageAspect->getFallbackChain());
$row = $pageRepository->getLanguageOverlay($tableName, $row, $customLanguageAspect);Reviews 4
- 12.4 88793[BUGFIX] Apply fallback chain for Extbase entities with language sets
- 13.4 88792[BUGFIX] Apply fallback chain for Extbase entities with language sets
- main 87036[BUGFIX] Apply fallback chain for Extbase entities with language sets
- main 87095[POC] "Apply fallback chain for Extbase entities w/language sets" tests
Related issues 1
History 714
-
Pascal Geldmacher commented <span data-processor="relativetime" data-value="2024-07-17T09:46:01+00:00" > 07/17/24, 09:46 </span>
I have the same problem.
I found out that the function in Backend.php is the problem.
/** * Returns the object with the (internal) identifier, if it is known to the * backend. Otherwise NULL is returned. * * @param string $identifier * @param string $className * @return object|null The object for the identifier if it is known, or NULL */ public function getObjectByIdentifier($identifier, $className) { if ($this->session->hasIdentifier($identifier, $className)) { return $this->session->getObjectByIdentifier($identifier, $className); } $query = $this->persistenceManager->createQueryForType($className); $query->getQuerySettings()->setRespectStoragePage(false); $query->getQuerySettings()->setRespectSysLanguage(false); // This allows to fetch IDs for languages for default language AND language IDs // This is especially important when using the PropertyMapper of the Extbase MVC part to get // an object of the translated version of the incoming ID of a record. $languageAspect = $query->getQuerySettings()->getLanguageAspect(); $languageAspect = new LanguageAspect( $languageAspect->getId(), $languageAspect->getContentId(), $languageAspect->getOverlayType() === LanguageAspect::OVERLAYS_OFF ? LanguageAspect::OVERLAYS_ON_WITH_FLOATING : $languageAspect->getOverlayType() ); $query->getQuerySettings()->setLanguageAspect($languageAspect); return $query->matching($query->equals('uid', $identifier))->execute()->getFirst(); }The code get the languageAspect from the QuerySettings with the correct fallbackchain and then, I dont’ know why but ok, created a new LanguageAspect object but without the fallbackchain, as fourth parameter.
I think that this would be the correct implementation, wouldn’t it?
$languageAspect = $query->getQuerySettings()->getLanguageAspect(); $languageAspect = new LanguageAspect( $languageAspect->getId(), $languageAspect->getContentId(), $languageAspect->getOverlayType() === LanguageAspect::OVERLAYS_OFF ? LanguageAspect::OVERLAYS_ON_WITH_FLOATING : $languageAspect->getOverlayType(), $languageAspect->getFallbackChain() ); -
Gerrit Code Review pushed patch set 1 for main to change 87036 status
NewUnder Review <span data-processor="relativetime" data-value="2024-11-18T15:39:13+00:00" > 11/18/24, 15:39 </span> -
Gerrit Code Review pushed patch set 2 for main to change 87036 <span data-processor="relativetime" data-value="2024-11-20T04:27:43+00:00" > 11/20/24, 04:27 </span>
-
Gerrit Code Review pushed patch set 3 for main to change 87036 <span data-processor="relativetime" data-value="2025-03-22T19:13:46+00:00" > 03/22/25, 19:13 </span>
-
Benni Mack changed Related to #91781 <span data-processor="relativetime" data-value="2025-03-22T19:16:03+00:00" > 03/22/25, 19:16 </span>
-
Benni Mack commented and changed status
Under ReviewResolved done0 %100 % <span data-processor="relativetime" data-value="2025-03-24T20:05:10+00:00" > 03/24/25, 20:05 </span>Applied in changeset commit:efc43dcc45173bb9b2c49dde6db3293b7f8c2d97.
-
Gerrit Code Review pushed patch set 1 for 13.4 to change 88792 status
ResolvedUnder Review <span data-processor="relativetime" data-value="2025-03-27T10:58:45+00:00" > 03/27/25, 10:58 </span> -
Gerrit Code Review pushed patch set 1 for 12.4 to change 88793 <span data-processor="relativetime" data-value="2025-03-27T10:59:31+00:00" > 03/27/25, 10:59 </span>
-
Gerrit Code Review pushed patch set 2 for 12.4 to change 88793 <span data-processor="relativetime" data-value="2025-03-27T11:35:28+00:00" > 03/27/25, 11:35 </span>
-
Benni Mack commented and changed status
Under ReviewResolved <span data-processor="relativetime" data-value="2025-03-27T11:40:09+00:00" > 03/27/25, 11:40 </span>Applied in changeset commit:e39cafbf21ffa028948bf72979160b581891009f.
-
Gerrit Code Review pushed patch set 3 for 12.4 to change 88793 status
ResolvedUnder Review <span data-processor="relativetime" data-value="2025-03-27T11:53:10+00:00" > 03/27/25, 11:53 </span> -
Benni Mack commented and changed status
Under ReviewResolved <span data-processor="relativetime" data-value="2025-03-27T12:05:09+00:00" > 03/27/25, 12:05 </span>Applied in changeset commit:bf6198de38d64c327b88ac0c7d816067619d63ec.
-
Benni Mack changed status
ResolvedClosed <span data-processor="relativetime" data-value="2025-12-02T14:33:19+00:00" > 12/02/25, 14:33 </span>
*Topic*
In a site with multiple languages and fallback chains configured, extbase models retrieved by an extbase repository do not respect the configured fallback chains.
Example
SiteConfig (only relevant parts):
Extbase Models in DB:
Using an extbase repository $repository->findAll() returns the following results in language=5:
instead of the expected result:
I’ve tracked the problem down to
\TYPO3\CMS\Extbase\Persistence\Generic\Storage\Typo3DbBackend->overlayLanguageAndWorkspaceForSingleRecord
in line 540 a new instance of LanguageAspect is created but without handing over the fallbackChain of the original languageAspect:
I am not sure, if this is done with purpose, but the pageRepository further more does not know about the configured fallbackChain and so cannot return the correct record. In my opinion the above code should look like this: