I am trying to get translated FAL image in extbase but it gives me default language FAL image.
I am using TYPO3 7.6.16. Its a multi-language website. I have created 2 website languages 1) English, 2) Spanish and the default one is Dutch.
Currently I am fetching data from repository and it gives me model with the same FAL image in both translated version and in original version of the record.
How Can I get translated FAL image using extbase (not in Fluid), because I want to return it to JSON response?
Here is the code:
Controller:
$posts = $this->postRepository->findByLanguage($langId);
foreach($posts as $post) {
$output[] = [
'uid' => $post->getUid(),
'title' => $post->getTitle(),
'image' => $post->getImage()->getOriginalResource()->getOriginalFile()->getPublicUrl()
];
}
header('Content-Type: application/json');
echo json_encode($output);
exit();
Here I am getting default language FAL image instead of localised on line $post->getImage()->getOriginalResource()->getOriginalFile()->getPublicUrl()
Repository:
/**
* @return array|\TYPO3\CMS\Extbase\Persistence\QueryResultInterface
*/
public function findByLanguage($langId, $postId = 0)
{
$query = $this->createQuery();
$query->getQuerySettings()->setRespectStoragePage(FALSE);
$query->getQuerySettings()->setRespectSysLanguage(TRUE);
$query->getQuerySettings()->setLanguageUid($langId);
if ($postId) {
$query->matching(
$query->equals('uid' , $postId)
);
return $query->execute()->getFirst();
}
return $query->execute();
}
Model:
/**
* title
*
* @var string
*/
protected $title;
/**
* image
*
* @var \TYPO3\CMS\Extbase\Domain\Model\FileReference
*/
protected $image = null;
/**
* @return bool $title
*/
public function getTitle() {
return $this->title;
}
/**
* @param string $title
* @return void
*/
public function setTitle($title) {
$this->title = $title;
}
/**
* @return \TYPO3\CMS\Extbase\Domain\Model\FileReference $image
*/
public function getImage() {
return $this->image;
}
/**
* @param \TYPO3\CMS\Extbase\Domain\Model\FileReference $image
* @return void
*/
public function setImage(\TYPO3\CMS\Extbase\Domain\Model\FileReference $image) {
$this->image = $image;
}