3

For my form plugin I'm using a global set of fields. These can be set in 2 languages default and en.

Problem is whenever I try to output them I cant dynamically make them use the current site locale/multi-site.

This is the current code:

$localeHandle = Craft::$app->getSites()->getCurrentSite()->handle;
    // form texts
    $entries = GlobalSet::find()
        ->siteId('*')
        ->site($localeHandle)
        ->handle('popupContact')
        ->asArray()
        ->one();

If $localeHandle is set to either default or en it works. I cant figure out how to get the handle though. Documentation doesn't state anything either.

Edit: Craft::$app->getSites()->getCurrentSite()->handle; returns the default site handle.

1 Answer 1

3

I don't know if this was the problem you were having but I was not including the site's first URL segment like /en/ (in your example) with the controller action URL. So you'd want to post to /en/actions/pluginHandle/controllerClass/actionMethod to get the English site back when using Craft::$app->getSites()->getCurrentSite() in your plugin.

I posted a more thorough answer to the same problem in another ticket: https://craftcms.stackexchange.com/a/33941/4433

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.