Trying to understand $query->getQuerySettings()->setRespectSysLanguage

Hi all,

I have a custom news extension and noticed that when trying to query a translated article inside the detailAction, the query always returned null.

    public function detailAction(string $id = null): ResponseInterface {
        if (is_string($id)) {
            $query = $this->newsArticleRepository->createQuery();
            $this->newsArticle = $query->matching($query->equals('uid', $id))->execute()->getFirst();
        }

When echoing $id I can see that the id is always the uid of the original record, even when I’m accessing the detail page in another language. When I’m not in the default language, the query returns null instead of the article. This makes sense (I guess?) because there is some language stuff happening in the background.

When trying to fix the query for translated records, I found that setting setRespectSysLanguage(false) does the trick and the translated record is returned.

But why? My initial assumption was that setting setRespectSysLanguage(false) will ignore all language related settings and fetch the original record (since $id is always the same).
Is this even the correct approach for my case? At least it works. (I also tried setting the languageAspect of the query, which seemingly did nothing.)

First of all, TYPO3 is doing the translation stuff on its own.
You don’t need to act in any way.

I stumbled upon your variable in the function.
Why do you use string for an integer ID?

I’d suggest to handle your Model in the variable:

public function detailAction(\Vendor\Extension\Classes\Domain\Model\YourNewsModel $newsArticle)

Then TYPO3 is doing the magic with the translated record and you don’t need to argue about the repository and you can remove the following lines.

Why do you use string for an integer ID?

I picked it up somewhere and went with it ever since because it worked.

public function detailAction(\Vendor\Extension\Classes\Domain\Model\YourNewsModel $newsArticle)

I don’t quite understand how this would work. I believe you are saying I should fetch all article details in a listAction (which I’m doing) and pass the whole article as an argument to f:link.action?

Currently I do this to call the detailAction:

<f:for each="{items}" as="article">
    <f:link.action
        action="detail"
        pluginName="NewsDetail"
        arguments="{id: article.uid}"
        pageUid="{detailPageId}"
    >
...

What would be the benefit of passing the whole article besides not having to fetch it again?