From 5b09c6cddaf71d30001b03b50d30069062de77e2 Mon Sep 17 00:00:00 2001 From: Rouven Bardtke | Paints Date: Thu, 14 Apr 2016 13:04:47 +0200 Subject: [PATCH] [FIX] Fix translations handling for file references in Extbase --- .../Classes/Domain/Model/FileReference.php | 2 +- .../Persistence/Generic/Mapper/ColumnMap.php | 19 +++++++++++++++++++ .../Generic/Mapper/DataMapFactory.php | 4 ++++ .../Persistence/Generic/Mapper/DataMapper.php | 7 ++++++- 4 files changed, 30 insertions(+), 2 deletions(-) diff --git a/typo3/sysext/extbase/Classes/Domain/Model/FileReference.php b/typo3/sysext/extbase/Classes/Domain/Model/FileReference.php index cb070140738a..8a197a699238 100755 --- a/typo3/sysext/extbase/Classes/Domain/Model/FileReference.php +++ b/typo3/sysext/extbase/Classes/Domain/Model/FileReference.php @@ -41,7 +41,7 @@ public function setOriginalResource(\TYPO3\CMS\Core\Resource\FileReference $orig */ public function getOriginalResource() { if ($this->originalResource === NULL) { - $this->originalResource = \TYPO3\CMS\Core\Resource\ResourceFactory::getInstance()->getFileReferenceObject($this->getUid()); + $this->originalResource = \TYPO3\CMS\Core\Resource\ResourceFactory::getInstance()->getFileReferenceObject($this->_localizedUid); } return $this->originalResource; diff --git a/typo3/sysext/extbase/Classes/Persistence/Generic/Mapper/ColumnMap.php b/typo3/sysext/extbase/Classes/Persistence/Generic/Mapper/ColumnMap.php index 831bc54020c8..32ff4b54a9db 100755 --- a/typo3/sysext/extbase/Classes/Persistence/Generic/Mapper/ColumnMap.php +++ b/typo3/sysext/extbase/Classes/Persistence/Generic/Mapper/ColumnMap.php @@ -165,6 +165,25 @@ class ColumnMap { */ protected $internalType; + /** + * @var bool + */ + protected $relationsOverriddenByTranslation; + + /** + * @return boolean + */ + public function isRelationsOverriddenByTranslation() { + return $this->relationsOverriddenByTranslation; + } + + /** + * @param boolean $relationsOverriddenByTranslation + */ + public function setRelationsOverriddenByTranslation($relationsOverriddenByTranslation) { + $this->relationsOverriddenByTranslation = $relationsOverriddenByTranslation; + } + /** * Constructs a Column Map * diff --git a/typo3/sysext/extbase/Classes/Persistence/Generic/Mapper/DataMapFactory.php b/typo3/sysext/extbase/Classes/Persistence/Generic/Mapper/DataMapFactory.php index 4741d106629e..18f5e2d7dca8 100755 --- a/typo3/sysext/extbase/Classes/Persistence/Generic/Mapper/DataMapFactory.php +++ b/typo3/sysext/extbase/Classes/Persistence/Generic/Mapper/DataMapFactory.php @@ -296,6 +296,10 @@ protected function setRelations(ColumnMap $columnMap, $columnConfiguration, $pro } else { $columnMap->setTypeOfRelation(ColumnMap::RELATION_NONE); } + if (isset($columnConfiguration['behaviour']['localizationMode'])) { + $columnMap->setRelationsOverriddenByTranslation($columnConfiguration['behaviour']['localizationMode'] !== 'keep'); + } + return $columnMap; } diff --git a/typo3/sysext/extbase/Classes/Persistence/Generic/Mapper/DataMapper.php b/typo3/sysext/extbase/Classes/Persistence/Generic/Mapper/DataMapper.php index c168fbffa821..b1fe5f9cebcd 100755 --- a/typo3/sysext/extbase/Classes/Persistence/Generic/Mapper/DataMapper.php +++ b/typo3/sysext/extbase/Classes/Persistence/Generic/Mapper/DataMapper.php @@ -375,7 +375,11 @@ protected function getPreparedQuery(\TYPO3\CMS\Extbase\DomainObject\DomainObject protected function getConstraint(\TYPO3\CMS\Extbase\Persistence\QueryInterface $query, \TYPO3\CMS\Extbase\DomainObject\DomainObjectInterface $parentObject, $propertyName, $fieldValue = '', $relationTableMatchFields = array()) { $columnMap = $this->getDataMap(get_class($parentObject))->getColumnMap($propertyName); if ($columnMap->getParentKeyFieldName() !== NULL) { - $constraint = $query->equals($columnMap->getParentKeyFieldName(), $parentObject); + if ($columnMap->isRelationsOverriddenByTranslation()) { + $constraint = $query->equals($columnMap->getParentKeyFieldName(), $parentObject->_getProperty('_localizedUid')); + } else { + $constraint = $query->equals($columnMap->getParentKeyFieldName(), $parentObject); + } if ($columnMap->getParentTableFieldName() !== NULL) { $constraint = $query->logicalAnd($constraint, $query->equals($columnMap->getParentTableFieldName(), $this->getDataMap(get_class($parentObject))->getTableName())); } @@ -387,6 +391,7 @@ protected function getConstraint(\TYPO3\CMS\Extbase\Persistence\QueryInterface $ $constraint = $query->logicalAnd($constraint, $query->equals($relationTableMatchFieldName, $relationTableMatchFieldValue)); } } + return $constraint; }