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.
1 Answer
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?– a-amCommented Mar 21, 2016 at 16:46
-
Yeah - its in the answer above; Craft.locale Commented Mar 21, 2016 at 16:49
-
That only grabs the CP's locale not the currently select locale in the edit entry view.– a-amCommented Mar 21, 2016 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. Commented Mar 21, 2016 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.– a-amCommented Mar 29, 2016 at 18:19