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 echo
ing $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.)