#88886DataMapper: Consider languageOverlayMode "hideNonTranslated" when getting relations using consistentTranslationOverlayHandling
Description
The language overlay handling doesn’t work properly using the new “consistentTranslationOverlayHandling” when getting DB relations if the language overlay mode is “hideNonTranslated” (fallbackType: strict).
Problem:
At the moment the languageOverlayMode is always set to true as
> we always want to overlay relations as most of the time they are stored in db using default lang uids
That’s correct. However, if the configured language overlay mode is “hideNonTranslated” (fallbackType: strict), we need to consider this.
Otherwise, if there’s no translation, the default relation/row isn’t removed in sysext/frontend/Classes/Page/PageRepository.php:790 (v9) resp. sysext/core/Classes/Domain/Repository/PageRepository.php:628 (v10) (called by $pageRepository->getRecordOverlay() in Typo3DbBackend::overlayLanguageAndWorkspace).
Solution:
1. Consider “hideNonTranslated” already when creating the parent object’s query, so it can be passed to the sub query later on.
sysext/extbase/Classes/Persistence/Generic/Backend.php:
275 275 public function getObjectByIdentifier($identifier, $className)
276 276 {
277 277 if ($this->session->hasIdentifier($identifier, $className)) {
278 278 return $this->session->getObjectByIdentifier($identifier, $className);
279 279 }
280 280 $query = $this->persistenceManager->createQueryForType($className);
281 281 $query->getQuerySettings()->setRespectStoragePage(false);
282 282 $query->getQuerySettings()->setRespectSysLanguage(false);
283 - $query->getQuerySettings()->setLanguageOverlayMode(true);
283 + if ($query->getQuerySettings()->getLanguageOverlayMode() !== 'hideNonTranslated') {
284 + $query->getQuerySettings()->setLanguageOverlayMode(true);
285 + }
284 286 return $query->matching($query->equals('uid', $identifier))->execute()->getFirst();
285 287 }
2. Pass “hideNonTranslated” to sub query.
sysext/extbase/Classes/Persistence/Generic/Mapper/DataMapper.php:
456 456 if ($this->configurationManager->isFeatureEnabled('consistentTranslationOverlayHandling')) {
457 457 //we always want to overlay relations as most of the time they are stored in db using default lang uids
458 458 $query->getQuerySettings()->setLanguageOverlayMode(true);
459 459 if ($this->query) {
460 460 $query->getQuerySettings()->setLanguageUid($this->query->getQuerySettings()->getLanguageUid());
461 + if ($this->query->getQuerySettings()->getLanguageOverlayMode() === 'hideNonTranslated') {
462 + $query->getQuerySettings()->setLanguageOverlayMode('hideNonTranslated');
463 + }
461 464
462 465 if ($dataMap->getLanguageIdColumnName() !== null && !$this->query->getQuerySettings()->getRespectSysLanguage()) {Reviews 2
Related issues 5
- Bug #82363Make Extbase translation handling consistent with typoscript
- Bug #89131Records that are only available in specific language (no default parent) are not considered using consistentTranslationOverlayHandling
- Feature #97926Use LanguageAspect in Extbase Persistence
- Bug #110025ObjectStorage->contains not working anymore with overlays off
- Bug #110498sys_file_reference value of sys_language_uid is assigned with a value of 0 in a translated model if the referenced sys_file has been used by a base language object