1
votes

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;
}
1
Can you post your code?Thomas Löffler
@ThomasLöffler I have now added code, please check my question.Ravi Sachaniya

1 Answers

0
votes

There was a bug where the FAL records (sys_file_reference) of translated (copy translate) contents did not get the lanuguage id of the translation. I made a bugfix for that: https://github.com/BenjaminBeck/bdm_bugfix_translatecopy - maybe thats your issue?