[TYPO3-mvc] Get Domain Object with forced default language
Sebastian Michaelsen
sebastian.gebhard at gmail.com
Thu Dec 30 01:17:29 CET 2010
Hi,
I work on an extbase extension for a website with multiple languages. Some of the fields of my model
are the same in every of the 5 languages and the editors don't want to have to put the same image
into the 4 translations of a record.
My idea was to create a fallback mechanism. If a foreign language record has no image, get the image
from default language.
Example: Default language is English, one of the foreign languages is German. I have a product with
an image field, but it's only filled in the default language version. In German it's empty and
should be filled automatically from the default language.
So my getter looks like:
/**
* Getter for image
*
* @return string image
*/
public function getImage() {
if($this->image) {
return $this->image;
} else {
return $this->getDefaultLanguageValue('image');
}
}
But obviously i need to have a domain model object in default language. For that i built a
repository method to get the default language object for a given foreign language object:
/**
* Finds a default language product for the given product
*
* @param Tx_TechCatalog_Domain_Model_Product $product
*/
public function findDefaultLanguageProduct(Tx_TechCatalog_Domain_Model_Product $product) {
$query = $this->createQuery();
//Disable Language restriction
$querySettings = $this->objectManager->getObject('Tx_Extbase_Persistence_Typo3QuerySettings');
$querySettings->setRespectSysLanguage(FALSE);
$query->setQuerySettings($querySettings);
$uidConstraint = $query->equals('uid', $product->_getProperty('t3_origuid'));
$languageConstraint = $query->equals('sys_language_uid', 0);
return $query->matching($uidConstraint)->matching($languageConstraint)->execute();
}
This was my best try, but somehow I always get a record (or multiple records) in the current FE
language but not in default language as I wanted.
The key problem is: Query an object in default language, while FE is set to a foreign language.
Any help is appreciated.
Kind regards,
Sebastian
More information about the TYPO3-project-typo3v4mvc
mailing list