1

When using createElementSelectorModal() in a plugin, how do you make your source list show items from the current locale selected in the CP? It only seems to show the items from default locale no matter what locale you have selected.

2

The BaseElementSelectorModal class takes a second parameter settings, which can include a criteria object. This criteria object is used to create an ElementCriteriaModel on the server, which means it can have any property an ElementCriteriaModel can have – including locale:

var currentLocale = Craft.getLocalStorage('BaseElementIndex.locale') || Craft.locale;

var modal = Craft.createElementSelectorModal('Entry', {
    criteria : {
        locale : currentLocale
    }
});
  • Can you get the CP's currently selected locale form the js Craft class? – aran Mar 21 '16 at 16:46
  • Yeah - its in the answer above; Craft.locale – Mats Mikkel Rummelhoff Mar 21 '16 at 16:49
  • That only grabs the CP's locale not the currently select locale in the edit entry view. – aran Mar 21 '16 at 16:49
  • 1
    @aran Sorry, didn't understand that you were looking for the current element index locale. The easiest (only) way I know how to do that, is to look in localStorage – just updated my answer. – Mats Mikkel Rummelhoff Mar 21 '16 at 17:06
  • It appears the only way to get the current selected locale from an entry edit screen is via the local hidden input, which is not the same as BaseElementIndex.locale. – aran Mar 29 '16 at 18:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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