Geography-related suggest modes.
GeoSuggestions folder into
site/addons/ and run
php please update:addons.
fields: country: type: suggest display: Country mode: geo-suggestions.country
This will get you a list of countries with corresponding 2-letter ISO codes as values.
You can easily create your own suggest modes. This addon comes with rinvex/countries library which has a lot of country-related data.
For instance, say you want to have a nationality field with a suggest mode.
You can use
countries() helper to get the data for all countries and pick a value that you need.
For this particular scenario we need a key called
- Create a class
Play around with
php please tinkerto get the data you need. I came up with this:
collect(countries(true)) ->pluck('demonym') ->filter() ->values() ->all();
For this case I'm calling
countries(true)to get a bigger data set which includes a demonym for each country. I'm wrapping it inside
collect()to turn the array into a Laravel Collection to get many convenience methods it provides. Then I'm picking (plucking) a
demonymkey from each country record and filter the collection to get rid of empty records. After then I call
values()to get only values from the collection stripping the keys and finally
all()turn the collection back to an array.
suggestions()method like you would do for a suggest mode.
- Wrap the array you got in step 2 in
$this->map()call. This will make sure you data will be formatted in a way that Statamic expects. If you have a simple array, both values and text labels will be the same. But if you want to have different values simply make an assosiative array.
Finally, use your suggest mode in a fieldset with a suggest field:
fields: country: type: suggest display: Nationality mode: geo-suggestions.demonym