From 4adf097f8d7f7c9d5e89b4c191896746d0ac1dd1 Mon Sep 17 00:00:00 2001 From: Jochen Rau Date: Tue, 2 Mar 2010 15:49:26 +0000 Subject: [PATCH] [+TASK] Extbase (DomainObject): Added a "private" property _localizationParentUid to the AbstractDomainObject which is set to the uid of the sys_language_parent. [+CONFIGURATION] Extbase (Persistence): Added a new flag respectSysLanguage to the Typoe3QuerySettings (TRUE by default). If it is set to true a "sys_language_uid IN (-1,0)" query part will be added if applicable. [~TASK] Extbase (Persistence): Refactored getRows() and countRows() to avoid unnecessary calls to doLanguageAndWorkspaceOverlay(). [!!!][+FEATURE] Extbase (Persistence): It's now possible to edit localized domain models in the FE. Changes will be stored to the correct database row. This changes the behavior of mapping the uid to DomainObjects. The uid is now the "real" uid of the localized database tuple instead of the sys_language_parent. This may influence the $_GET parameters of cached pages as the uid is often part of the URI. Resolves #4639. [~TASK] Extbase (Persistence): Added $query->getQuerySettings()->setRespectSysLanguage(FALSE); to all methods fetching an object "byUid". [~TASK] Extbase (Persistence): Changed method signatures to Tx_Extbase_DomainObject_DomainObjectInterface instead of Tx_Extbase_DomainObject_AbstractEnty. --- .../DomainObject/AbstractDomainObject.php | 13 ++- .../Classes/MVC/Controller/Argument.php | 1 + .../extbase/Classes/Persistence/Backend.php | 5 +- .../Classes/Persistence/LazyLoadingProxy.php | 4 +- .../Classes/Persistence/LazyObjectStorage.php | 2 +- .../Classes/Persistence/Mapper/DataMapper.php | 42 ++++--- .../Classes/Persistence/Repository.php | 1 + .../Persistence/Storage/Typo3DbBackend.php | 106 +++++++++++------- .../Persistence/Typo3QuerySettings.php | 27 +++++ .../Typo3QuerySettingsInterface.php | 19 ++++ .../extbase/Classes/Property/Mapper.php | 1 + 11 files changed, 159 insertions(+), 62 deletions(-) diff --git a/typo3/sysext/extbase/Classes/DomainObject/AbstractDomainObject.php b/typo3/sysext/extbase/Classes/DomainObject/AbstractDomainObject.php index 7ca212e603c2..30f25afe0b50 100644 --- a/typo3/sysext/extbase/Classes/DomainObject/AbstractDomainObject.php +++ b/typo3/sysext/extbase/Classes/DomainObject/AbstractDomainObject.php @@ -38,6 +38,11 @@ abstract class Tx_Extbase_DomainObject_AbstractDomainObject implements Tx_Extbas */ protected $uid; + /** + * @var int The uid of the localization parent + */ + protected $_localizationParentUid; + /** * TRUE if the object is a clone * @var boolean @@ -80,9 +85,13 @@ abstract class Tx_Extbase_DomainObject_AbstractDomainObject implements Tx_Extbas * @return int the uid or NULL if none set yet. */ final public function getUid() { - return ($this->uid === NULL ? NULL : (int)$this->uid); + if ($this->uid !== NULL) { + return (int)$this->uid; + } else { + return NULL; + } } - + /** * Reconstitutes a property. Only for internal use. * diff --git a/typo3/sysext/extbase/Classes/MVC/Controller/Argument.php b/typo3/sysext/extbase/Classes/MVC/Controller/Argument.php index 8cc73d7b1555..bf5c5f76ed13 100644 --- a/typo3/sysext/extbase/Classes/MVC/Controller/Argument.php +++ b/typo3/sysext/extbase/Classes/MVC/Controller/Argument.php @@ -381,6 +381,7 @@ class Tx_Extbase_MVC_Controller_Argument { */ protected function findObjectByUid($uid) { $query = $this->queryFactory->create($this->dataType); + $query->getQuerySettings()->setRespectSysLanguage(FALSE); $result = $query->matching($query->withUid($uid))->execute(); $object = NULL; if (count($result) > 0) { diff --git a/typo3/sysext/extbase/Classes/Persistence/Backend.php b/typo3/sysext/extbase/Classes/Persistence/Backend.php index be6df24fc59e..2e52e4d97352 100644 --- a/typo3/sysext/extbase/Classes/Persistence/Backend.php +++ b/typo3/sysext/extbase/Classes/Persistence/Backend.php @@ -768,8 +768,7 @@ class Tx_Extbase_Persistence_Backend implements Tx_Extbase_Persistence_BackendIn protected function updateObject(Tx_Extbase_DomainObject_DomainObjectInterface $object, array &$row) { $tableName = $this->dataMapper->getDataMap(get_class($object))->getTableName(); $this->addCommonFieldsToRow($object, $row); - $uid = $object->getUid(); - $row['uid'] = $uid; + $row['uid'] = $object->getUid(); $res = $this->storageBackend->updateRow( $tableName, $row @@ -779,7 +778,7 @@ class Tx_Extbase_Persistence_Backend implements Tx_Extbase_Persistence_BackendIn } return $res; } - + /** * Returns a table row to be inserted or updated in the database * diff --git a/typo3/sysext/extbase/Classes/Persistence/LazyLoadingProxy.php b/typo3/sysext/extbase/Classes/Persistence/LazyLoadingProxy.php index ad20061b72d7..bb2088390587 100644 --- a/typo3/sysext/extbase/Classes/Persistence/LazyLoadingProxy.php +++ b/typo3/sysext/extbase/Classes/Persistence/LazyLoadingProxy.php @@ -55,7 +55,7 @@ class Tx_Extbase_Persistence_LazyLoadingProxy implements Iterator, Tx_Extbase_Pe * @var mixed */ private $fieldValue; - + /** * Constructs this proxy instance. * @@ -80,7 +80,7 @@ class Tx_Extbase_Persistence_LazyLoadingProxy implements Iterator, Tx_Extbase_Pe // it's parent... the result would be weird. if ($this->parentObject->_getProperty($this->propertyName) instanceof Tx_Extbase_Persistence_LazyLoadingProxy) { $dataMapper = Tx_Extbase_Dispatcher::getPersistenceManager()->getBackend()->getDataMapper(); - $objects = $dataMapper->fetchRelated($this->parentObject, $this->propertyName, $this->fieldValue, FALSE); + $objects = $dataMapper->fetchRelated($this->parentObject, $this->propertyName, $this->fieldValue, FALSE, FALSE); $propertyValue = $dataMapper->mapResultToPropertyValue($this->parentObject, $this->propertyName, $objects); $this->parentObject->_setProperty($this->propertyName, $propertyValue); $this->parentObject->_memorizeCleanState($this->propertyName); diff --git a/typo3/sysext/extbase/Classes/Persistence/LazyObjectStorage.php b/typo3/sysext/extbase/Classes/Persistence/LazyObjectStorage.php index dbb389af6ddc..9097053b911b 100644 --- a/typo3/sysext/extbase/Classes/Persistence/LazyObjectStorage.php +++ b/typo3/sysext/extbase/Classes/Persistence/LazyObjectStorage.php @@ -83,7 +83,7 @@ class Tx_Extbase_Persistence_LazyObjectStorage extends Tx_Extbase_Persistence_Ob protected function initializeStorage() { if (!$this->isInitialized) { $dataMapper = Tx_Extbase_Dispatcher::getPersistenceManager()->getBackend()->getDataMapper(); - $objects = $dataMapper->fetchRelated($this->parentObject, $this->propertyName, $this->fieldValue, FALSE); + $objects = $dataMapper->fetchRelated($this->parentObject, $this->propertyName, $this->fieldValue, FALSE, FALSE); $storage = array(); foreach ($objects as $object) { $storage[spl_object_hash($object)] = $object; diff --git a/typo3/sysext/extbase/Classes/Persistence/Mapper/DataMapper.php b/typo3/sysext/extbase/Classes/Persistence/Mapper/DataMapper.php index 5ca4b3fd1e72..7dfcf3f8c62a 100644 --- a/typo3/sysext/extbase/Classes/Persistence/Mapper/DataMapper.php +++ b/typo3/sysext/extbase/Classes/Persistence/Mapper/DataMapper.php @@ -184,7 +184,14 @@ class Tx_Extbase_Persistence_Mapper_DataMapper implements t3lib_Singleton { $className = get_class($object); $dataMap = $this->getDataMap($className); $properties = $object->_getProperties(); - $object->_setProperty('uid', $row->getValue('uid')); + $localizedUid = $row->getValue('_LOCALIZED_UID'); + if ($localizedUid !== NULL) { + $object->_setProperty('uid', $localizedUid); + $object->_setProperty('_localizationParentUid', $row->getValue('uid')); + } else { + $object->_setProperty('uid', $row->getValue('uid')); + } + unset($properties['uid']); foreach ($properties as $propertyName => $propertyValue) { if (!$dataMap->isPersistableProperty($propertyName)) continue; $columnMap = $dataMap->getColumnMap($propertyName); @@ -228,13 +235,14 @@ class Tx_Extbase_Persistence_Mapper_DataMapper implements t3lib_Singleton { /** * Fetches a collection of objects related to a property of a parent object * - * @param Tx_Extbase_DomainObject_AbstractEntity $parentObject The object instance this proxy is part of + * @param Tx_Extbase_DomainObject_DomainObjectInterface $parentObject The object instance this proxy is part of * @param string $propertyName The name of the proxied property in it's parent * @param mixed $fieldValue The raw field value. - * @param Tx_Extbase_Persistence_Mapper_DataMap $dataMap The corresponding Data Map of the property + * @param bool $enableLazyLoading A flag indication if the related objects should be lazy loaded + * @param bool $performLanguageOverlay A flag indication if the related objects should be localized * @return mixed The result */ - public function fetchRelated(Tx_Extbase_DomainObject_AbstractEntity $parentObject, $propertyName, $fieldValue = '', $enableLazyLoading = TRUE) { + public function fetchRelated(Tx_Extbase_DomainObject_DomainObjectInterface $parentObject, $propertyName, $fieldValue = '', $enableLazyLoading = TRUE, $performLanguageOverlay = TRUE) { $columnMap = $this->getDataMap(get_class($parentObject))->getColumnMap($propertyName); $propertyMetaData = $this->reflectionService->getClassSchema(get_class($parentObject))->getProperty($propertyName); if ($enableLazyLoading === TRUE && ($propertyMetaData['lazy'] || ($columnMap->getLoadingStrategy() !== Tx_Extbase_Persistence_Mapper_ColumnMap::STRATEGY_EAGER))) { @@ -244,7 +252,7 @@ class Tx_Extbase_Persistence_Mapper_DataMapper implements t3lib_Singleton { $result = t3lib_div::makeInstance('Tx_Extbase_Persistence_LazyLoadingProxy', $parentObject, $propertyName, $fieldValue); } } else { - $result = $this->fetchRelatedEager($parentObject, $propertyName, $fieldValue); + $result = $this->fetchRelatedEager($parentObject, $propertyName, $fieldValue, $performLanguageOverlay); } return $result; } @@ -252,26 +260,28 @@ class Tx_Extbase_Persistence_Mapper_DataMapper implements t3lib_Singleton { /** * Fetches the related objects from the storage backend. * - * @param Tx_Extbase_DomainObject_AbstractEntity $parentObject The object instance this proxy is part of + * @param Tx_Extbase_DomainObject_DomainObjectInterface $parentObject The object instance this proxy is part of * @param string $propertyName The name of the proxied property in it's parent * @param mixed $fieldValue The raw field value. + * @param bool $performLanguageOverlay A flag indication if the related objects should be localized * @return void */ - protected function fetchRelatedEager(Tx_Extbase_DomainObject_AbstractEntity $parentObject, $propertyName, $fieldValue = '') { + protected function fetchRelatedEager(Tx_Extbase_DomainObject_DomainObjectInterface $parentObject, $propertyName, $fieldValue = '', $performLanguageOverlay = TRUE) { if ($fieldValue === '') return array(); $query = $this->getPreparedQuery($parentObject, $propertyName, $fieldValue); + $query->getQuerySettings()->setRespectSysLanguage($performLanguageOverlay); return $query->execute(); } /** * Builds and returns the prepared query, ready to be executed. * - * @param Tx_Extbase_DomainObject_AbstractEntity $parentObject + * @param Tx_Extbase_DomainObject_DomainObjectInterface $parentObject * @param string $propertyName * @param string $fieldValue * @return void */ - protected function getPreparedQuery(Tx_Extbase_DomainObject_AbstractEntity $parentObject, $propertyName, $fieldValue = '') { + protected function getPreparedQuery(Tx_Extbase_DomainObject_DomainObjectInterface $parentObject, $propertyName, $fieldValue = '') { $columnMap = $this->getDataMap(get_class($parentObject))->getColumnMap($propertyName); $queryFactory = t3lib_div::makeInstance('Tx_Extbase_Persistence_QueryFactory'); $parentKeyFieldName = $columnMap->getParentKeyFieldName(); @@ -344,7 +354,7 @@ class Tx_Extbase_Persistence_Mapper_DataMapper implements t3lib_Singleton { * @param array $propertyMetaData The property meta data * @return void */ - public function mapResultToPropertyValue(Tx_Extbase_DomainObject_AbstractEntity $parentObject, $propertyName, $result) { + public function mapResultToPropertyValue(Tx_Extbase_DomainObject_DomainObjectInterface $parentObject, $propertyName, $result) { if ($result instanceof Tx_Extbase_Persistence_LoadingStrategyInterface) { $propertyValue = $result; } else { @@ -377,11 +387,11 @@ class Tx_Extbase_Persistence_Mapper_DataMapper implements t3lib_Singleton { /** * Counts the number of related objects assigned to a property of a parent object * - * @param Tx_Extbase_DomainObject_AbstractEntity $parentObject The object instance this proxy is part of + * @param Tx_Extbase_DomainObject_DomainObjectInterface $parentObject The object instance this proxy is part of * @param string $propertyName The name of the proxied property in it's parent * @param mixed $fieldValue The raw field value. */ - public function countRelated(Tx_Extbase_DomainObject_AbstractEntity $parentObject, $propertyName, $fieldValue = '') { + public function countRelated(Tx_Extbase_DomainObject_DomainObjectInterface $parentObject, $propertyName, $fieldValue = '') { $query = $this->getPreparedQuery($parentObject, $propertyName, $fieldValue); return $query->count(); } @@ -476,11 +486,11 @@ class Tx_Extbase_Persistence_Mapper_DataMapper implements t3lib_Singleton { /** * Returns the type of a child object. * - * @param Tx_Extbase_DomainObject_AbstractEntity $parentObject The object instance this proxy is part of + * @param Tx_Extbase_DomainObject_DomainObjectInterface $parentObject The object instance this proxy is part of * @param string $propertyName The name of the proxied property in it's parent * @return string The class name of the child object */ - protected function getType(Tx_Extbase_DomainObject_AbstractEntity $parentObject, $propertyName) { + protected function getType(Tx_Extbase_DomainObject_DomainObjectInterface $parentObject, $propertyName) { $propertyMetaData = $this->reflectionService->getClassSchema(get_class($parentObject))->getProperty($propertyName); $columnMap = $this->getDataMap(get_class($parentObject))->getColumnMap($propertyName); $childClassName = $columnMap->getChildClassName(); @@ -497,11 +507,11 @@ class Tx_Extbase_Persistence_Mapper_DataMapper implements t3lib_Singleton { /** * Returns the type of the elements inside an ObjectStorage or array. * - * @param Tx_Extbase_DomainObject_AbstractEntity $parentObject The object instance this proxy is part of + * @param Tx_Extbase_DomainObject_DomainObjectInterface $parentObject The object instance this proxy is part of * @param string $propertyName The name of the proxied property in it's parent * @return string The class name of the elements inside an ObjectStorage */ - protected function getElementType(Tx_Extbase_DomainObject_AbstractEntity $parentObject, $propertyName) { + protected function getElementType(Tx_Extbase_DomainObject_DomainObjectInterface $parentObject, $propertyName) { $propertyMetaData = $this->reflectionService->getClassSchema(get_class($parentObject))->getProperty($propertyName); $columnMap = $this->getDataMap(get_class($parentObject))->getColumnMap($propertyName); $childClassName = $columnMap->getChildClassName(); diff --git a/typo3/sysext/extbase/Classes/Persistence/Repository.php b/typo3/sysext/extbase/Classes/Persistence/Repository.php index eb3e8e9a65b4..0630dc771f21 100644 --- a/typo3/sysext/extbase/Classes/Persistence/Repository.php +++ b/typo3/sysext/extbase/Classes/Persistence/Repository.php @@ -236,6 +236,7 @@ class Tx_Extbase_Persistence_Repository implements Tx_Extbase_Persistence_Reposi $object = $this->identityMap->getObjectByIdentifier($uid, $this->objectType); } else { $query = $this->createQuery(); + $query->getQuerySettings()->setRespectSysLanguage(FALSE); $result = $query->matching($query->withUid($uid))->execute(); $object = NULL; if (count($result) > 0) { diff --git a/typo3/sysext/extbase/Classes/Persistence/Storage/Typo3DbBackend.php b/typo3/sysext/extbase/Classes/Persistence/Storage/Typo3DbBackend.php index 6b1a8035725f..3993752f6509 100644 --- a/typo3/sysext/extbase/Classes/Persistence/Storage/Typo3DbBackend.php +++ b/typo3/sysext/extbase/Classes/Persistence/Storage/Typo3DbBackend.php @@ -227,7 +227,9 @@ class Tx_Extbase_Persistence_Storage_Typo3DbBackend implements Tx_Extbase_Persis // debug($statement,-2); $result = $this->databaseHandle->sql_query($statement); $this->checkSqlErrors(); - return $this->getRowsFromResult($query->getSource(), $result); + $rows = $this->getRowsFromResult($query->getSource(), $result); + $rows = $this->doLanguageAndWorkspaceOverlay($query->getSource(), $rows); + return $rows; } /** @@ -246,8 +248,8 @@ class Tx_Extbase_Persistence_Storage_Typo3DbBackend implements Tx_Extbase_Persis $this->replacePlaceholders($statement, $parameters); $result = $this->databaseHandle->sql_query($statement); $this->checkSqlErrors(); - $tuples = $this->getRowsFromResult($query->getSource(), $result); - return current(current($tuples)); + $rows = $this->getRowsFromResult($query->getSource(), $result); + return current(current($rows)); } /** @@ -376,6 +378,9 @@ class Tx_Extbase_Persistence_Storage_Typo3DbBackend implements Tx_Extbase_Persis if ($querySettings->getRespectEnableFields()) { $this->addEnableFieldsStatement($tableName, $sql); } + if ($querySettings->getRespectSysLanguage()) { + $this->addSysLanguageStatement($tableName, $sql); + } if ($querySettings->getRespectStoragePage()) { $this->addPageIdStatement($tableName, $sql); } @@ -421,6 +426,10 @@ class Tx_Extbase_Persistence_Storage_Typo3DbBackend implements Tx_Extbase_Persis $this->addEnableFieldsStatement($leftTableName, $sql); $this->addEnableFieldsStatement($rightTableName, $sql); } + if ($querySettings->getRespectSysLanguage()) { + $this->addSysLanguageStatement($leftTableName, $sql); + $this->addSysLanguageStatement($rightTableName, $sql); + } if ($querySettings->getRespectStoragePage()) { $this->addPageIdStatement($leftTableName, $sql); $this->addPageIdStatement($rightTableName, $sql); @@ -634,7 +643,22 @@ class Tx_Extbase_Persistence_Storage_Typo3DbBackend implements Tx_Extbase_Persis } } } - + + /** + * Builds the language field statement + * + * @param string $tableName The database table name + * @param array &$sql The query parts + * @return void + */ + protected function addSysLanguageStatement($tableName, array &$sql) { + if (is_array($GLOBALS['TCA'][$tableName]['ctrl'])) { + if(isset($GLOBALS['TCA'][$tableName]['ctrl']['languageField']) && $GLOBALS['TCA'][$tableName]['ctrl']['languageField'] !== NULL) { + $sql['additionalWhereClause'][] = $tableName . '.' . $GLOBALS['TCA'][$tableName]['ctrl']['languageField'] . ' IN (0,-1)'; + } + } + } + /** * Builds the page ID checking statement * @@ -707,8 +731,7 @@ class Tx_Extbase_Persistence_Storage_Typo3DbBackend implements Tx_Extbase_Persis } /** - * Transforms a Resource from a database query to an array of rows. Performs the language and - * workspace overlay before. + * Transforms a Resource from a database query to an array of rows. * * @param Tx_Extbase_Persistence_QOM_SourceInterface $source The source (selector od join) * @param resource $result The result @@ -717,14 +740,9 @@ class Tx_Extbase_Persistence_Storage_Typo3DbBackend implements Tx_Extbase_Persis protected function getRowsFromResult(Tx_Extbase_Persistence_QOM_SourceInterface $source, $result) { $rows = array(); while ($row = $this->databaseHandle->sql_fetch_assoc($result)) { - if ($source instanceof Tx_Extbase_Persistence_QOM_SelectorInterface) { - $row = $this->doLanguageAndWorkspaceOverlay($source->getSelectorName(), $row); - } else if ($source instanceof Tx_Extbase_Persistence_QOM_JoinInterface) { - $row = $this->doLanguageAndWorkspaceOverlay($source->getLeft()->getSelectorName(), $row); - } if (is_array($row)) { // TODO Check if this is necessary, maybe the last line is enough - $arrayKeys = range(0,count($row)); + $arrayKeys = range(0, count($row)); array_fill_keys($arrayKeys, $row); $rows[] = $row; } @@ -736,46 +754,58 @@ class Tx_Extbase_Persistence_Storage_Typo3DbBackend implements Tx_Extbase_Persis * Performs workspace and language overlay on the given row array. The language and workspace id is automatically * detected (depending on FE or BE context). You can also explicitly set the language/workspace id. * - * @param Tx_Extbase_Persistence_Mapper_DataMap $dataMap + * @param Tx_Extbase_Persistence_QOM_SourceInterface $source The source (selector od join) * @param array $row The row array (as reference) * @param string $languageUid The language id * @param string $workspaceUidUid The workspace id * @return void */ - protected function doLanguageAndWorkspaceOverlay($tableName, array $row, $languageUid = NULL, $workspaceUid = NULL) { - if (!($this->pageSelectObject instanceof t3lib_pageSelect)) { - if (TYPO3_MODE == 'FE') { - if (is_object($GLOBALS['TSFE'])) { - $this->pageSelectObject = $GLOBALS['TSFE']->sys_page; + protected function doLanguageAndWorkspaceOverlay(Tx_Extbase_Persistence_QOM_SourceInterface $source, array $rows, $languageUid = NULL, $workspaceUid = NULL) { + $overlayedRows = array(); + foreach ($rows as $row) { + if (!($this->pageSelectObject instanceof t3lib_pageSelect)) { + if (TYPO3_MODE == 'FE') { + if (is_object($GLOBALS['TSFE'])) { + $this->pageSelectObject = $GLOBALS['TSFE']->sys_page; + } else { + require_once(PATH_t3lib . 'class.t3lib_page.php'); + $this->pageSelectObject = t3lib_div::makeInstance('t3lib_pageSelect'); + } } else { require_once(PATH_t3lib . 'class.t3lib_page.php'); - $this->pageSelectObject = t3lib_div::makeInstance('t3lib_pageSelect'); + $this->pageSelectObject = t3lib_div::makeInstance( 't3lib_pageSelect' ); } - } else { - require_once(PATH_t3lib . 'class.t3lib_page.php'); - $this->pageSelectObject = t3lib_div::makeInstance( 't3lib_pageSelect' ); - } - } - if (is_object($GLOBALS['TSFE'])) { - if ($languageUid === NULL) { - $languageUid = $GLOBALS['TSFE']->sys_language_uid; } - if ($workspaceUid !== NULL) { + if (is_object($GLOBALS['TSFE'])) { + if ($languageUid === NULL) { + $languageUid = $GLOBALS['TSFE']->sys_language_uid; + } + if ($workspaceUid !== NULL) { + $this->pageSelectObject->versioningWorkspaceId = $workspaceUid; + } + } else { + if ($languageUid === NULL) { + $languageUid = intval(t3lib_div::_GP('L')); + } + if ($workspaceUid === NULL) { + $workspaceUid = $GLOBALS['BE_USER']->workspace; + } $this->pageSelectObject->versioningWorkspaceId = $workspaceUid; } - } else { - if ($languageUid === NULL) { - $languageUid = intval(t3lib_div::_GP('L')); + if ($source instanceof Tx_Extbase_Persistence_QOM_SelectorInterface) { + $tableName = $source->getSelectorName(); + } elseif ($source instanceof Tx_Extbase_Persistence_QOM_JoinInterface) { + $tableName = $source->getLeft()->getSelectorName(); } - if ($workspaceUid === NULL) { - $workspaceUid = $GLOBALS['BE_USER']->workspace; + $this->pageSelectObject->versionOL($tableName, $row, TRUE); + if(isset($GLOBALS['TCA'][$tableName]['ctrl']['languageField']) && $GLOBALS['TCA'][$tableName]['ctrl']['languageField'] !== '') { + if (in_array($row[$GLOBALS['TCA'][$tableName]['ctrl']['languageField']], array(-1,0))) { + $row = $this->pageSelectObject->getRecordOverlay($tableName, $row, $languageUid); + } } - $this->pageSelectObject->versioningWorkspaceId = $workspaceUid; + $overlayedRows[] = $row; } - $this->pageSelectObject->versionOL($tableName, $row, TRUE); - $row = $this->pageSelectObject->getRecordOverlay($tableName, $row, $languageUid, ''); //'hideNonTranslated' - // TODO Skip if empty languageoverlay (languagevisibility) - return $row; + return $overlayedRows; } /** diff --git a/typo3/sysext/extbase/Classes/Persistence/Typo3QuerySettings.php b/typo3/sysext/extbase/Classes/Persistence/Typo3QuerySettings.php index bfb0352d25ec..05a12b7ccced 100644 --- a/typo3/sysext/extbase/Classes/Persistence/Typo3QuerySettings.php +++ b/typo3/sysext/extbase/Classes/Persistence/Typo3QuerySettings.php @@ -48,6 +48,12 @@ class Tx_Extbase_Persistence_Typo3QuerySettings implements Tx_Extbase_Persistenc */ protected $respectEnableFields = TRUE; + /** + * Flag if the sys_language_uid should be respected (default is TRUE). + * @var boolean + */ + protected $respectSysLanguage = TRUE; + /** * Flag if the the query result should be returned as raw QueryResult. * @var boolean @@ -75,6 +81,27 @@ class Tx_Extbase_Persistence_Typo3QuerySettings implements Tx_Extbase_Persistenc return $this->respectStoragePage; } + /** + * Sets the flag if a and language overlay should be performed. + * + * @param $respectEnableFields TRUE if a and language overlay should be performed. + * @return $this (fluent interface) + * @api + */ + public function setRespectSysLanguage($respectSysLanguage) { + $this->respectSysLanguage = $respectSysLanguage; + return $this; + } + + /** + * Returns the state, if a and language overlay should be performed. + * + * @return boolean TRUE, if a and language overlay should be performed; otherwise FALSE. + */ + public function getRespectSysLanguage() { + return $this->respectSysLanguage; + } + /** * Sets the flag if the visibility in the frontend should be respected. * diff --git a/typo3/sysext/extbase/Classes/Persistence/Typo3QuerySettingsInterface.php b/typo3/sysext/extbase/Classes/Persistence/Typo3QuerySettingsInterface.php index e008c192a3b1..1ace0abb26c6 100644 --- a/typo3/sysext/extbase/Classes/Persistence/Typo3QuerySettingsInterface.php +++ b/typo3/sysext/extbase/Classes/Persistence/Typo3QuerySettingsInterface.php @@ -54,10 +54,28 @@ interface Tx_Extbase_Persistence_Typo3QuerySettingsInterface extends Tx_Extbase_ */ public function setRespectEnableFields($respectEnableFields); + /** + * Sets the flag if if the sys language should be respected. + * + * @param $respectSysLanguage TRUE if the sys language should be respected. + * @return $this (fluent interface) + * @api + */ + public function setRespectSysLanguage($respectSysLanguage); + + /** + * Returns the state, if the sys language should be respected. + * + * @return boolean TRUE, if the sys language should be respected; otherwise FALSE. + */ + public function getRespectSysLanguage(); + + /** * Sets the state, if the QueryResult should be returned unmapped. * * @return boolean TRUE, if the QueryResult should be returned unmapped; otherwise FALSE. + * @api */ public function setReturnRawQueryResult($returnRawQueryResult); @@ -65,6 +83,7 @@ interface Tx_Extbase_Persistence_Typo3QuerySettingsInterface extends Tx_Extbase_ * Returns the state, if the QueryResult should be returned unmapped. * * @return boolean TRUE, if the QueryResult should be returned unmapped; otherwise FALSE. + * @api */ public function getReturnRawQueryResult(); diff --git a/typo3/sysext/extbase/Classes/Property/Mapper.php b/typo3/sysext/extbase/Classes/Property/Mapper.php index 2f78a5837d6b..1379a001d2fc 100644 --- a/typo3/sysext/extbase/Classes/Property/Mapper.php +++ b/typo3/sysext/extbase/Classes/Property/Mapper.php @@ -305,6 +305,7 @@ class Tx_Extbase_Property_Mapper { */ protected function findObjectByUid($dataType, $uid) { $query = $this->queryFactory->create($dataType); + $query->getQuerySettings()->setRespectSysLanguage(FALSE); $result = $query->matching($query->withUid($uid))->execute(); $object = NULL; if (count($result) > 0) { -- 2.20.1