Incomplete language aspect

Issue #3 resolved
Rainer Becker created an issue

In https://bitbucket.org/99grad-team/nnrestapi/src/90713711c86351535b6cfa7dcdfa5add2dd35219/Classes/Controller/ApiController.php#lines-58:59 the LanguageAspect is created by just passing the id to the constructor. That way other properties like fallback handling that are set in SiteLanguage are missing and thus fetching data via Extbase might give wrong results.
I got better results using

/** @var ServerRequest $mvcRequest */
$mvcRequest = $request->getMvcRequest();
$language = $mvcRequest->getAttribute('language');
$languageAspect = LanguageAspectFactory::createFromSiteLanguage($language);
$context->setAspect('language', $languageAspect);

Thank you for you extension - the features look very promising. Maybe we get a unified Headless API for TYPO3 - go for it!
Btw: Is it intentionally that I could not change the donation amount to more than 1 €?

Comments (7)

  1. David Bascom

    Great - thanks for the Input! We‘ll integrate this in the next release.

    You seem to really know your way around localisation - could I approach you with an other open todo related to the nnrestapi?

    We need a hint, why the defined localisation fallback languages work fine when retrieving pages and content - but not when retrieving data/models from a Repository. If the record does not exist in the requested language, TYPO3 ignores the fallback language and always returns the data in the base language (0).

    Would be great to have a tipp!

    1€? Not intended… always happy for an extra large size coffee 🙂 thanks for asking! We‘ll check that too.

  2. David Bascom

    Incomplete language aspect
    Here is an idea how your suggestion could be implemented without breaking the feature to be able to use a custom determineLanguage() method:
    https://bitbucket.org/99grad-team/nnrestapi/src/7f7fb35d296b11d5bffeeda0d3c94015c5af18ff/Classes/Controller/ApiController.php#lines-60:65
    What do you think?

    “Fallback to default language (0) instead of language defined in config.yaml”
    Seems to be a common problem. Found no solution so far.
    https://stackoverflow.com/questions/69266363/tx-news-does-not-fallback-to-right-language
    https://www.typo3forum.net/discussion/82961/typo3-v9-sites-config-language-fallback

  3. Rainer Becker reporter

    Your fix looks good and works for me, that’s great!

    My two cents regarding fallback behaviour: make nnrest behave like core as much as possible. If core extbase handling is doing things wrong I would not try to overcome this in your extension. There are just too many scenarios regarding language handling… hard to track them all 😉

  4. David Bascom

    Yes, you are right – that is a very good point. And there really does seem to be a couple of problems related to the localisation in the core. We’ll keep an eye on this topic until there is a solution.
    Thanks again for your contribution!

  5. Log in to comment