Reputation: 63
I'm trying to create an entity with a oneToMany relation and criteria like this
/**
* Get translatedData
*
* @return translatedData collection
*/
public function getTranslatedData($language) {
$criteria = Criteria::create()->where(Criteria::expr()->eq("language", $language));
$result = $this->getAllTranslatedData()->matching($criteria)[0];
if (count($result) == 0){
$criteria = Criteria::create()->where(Criteria::expr()->eq("language", 'en'));
$result = $this->getAllTranslatedData()->matching($criteria)[0];
}
return $result;
}
Basically I want to pass the locale to the entity, so it will return the translatedData in the locale language in the twig template just calling {{ mainEntity.translatedData.property }} (if there's no translated data in that language, it will fallback to 'en') but doing a find() on the mainEntity I'm unable to pass any param to this function.
Any idea is appreciated.
Thanks
Upvotes: 0
Views: 83
Reputation: 2444
Instead of calling the property translatedData.property
on your entity you can simply call your method directly in twig:
{{ mainEntity.getTranslatedData('your_language') }}
It will allow you to pass a parameter.
Upvotes: 1