[TYPO3-mvc] Get a model in forced default language

Sebastian Michaelsen sebastian.gebhard at gmail.com
Thu Dec 30 01:13:19 CET 2010


Hi,

I work on an extbase extension for a website with multiple languages. Some of the fields of my 
property 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_MyExt_Domain_Model_Product $product
  */
public function findDefaultLanguageProduct(Tx_MyExt_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->getUid());
	$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.

Any help is appreciated.

Kind regards,
Sebastian


More information about the TYPO3-project-typo3v4mvc mailing list