-
-
Notifications
You must be signed in to change notification settings - Fork 489
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[5.x] Dictionaries #10380
base: 5.x
Are you sure you want to change the base?
[5.x] Dictionaries #10380
Conversation
Ready for Flat Camp ⛺
c1715a7
to
0641a34
Compare
Hello. Can we relate 2 (or more) dictionnaries? ie a Country dictionnary and a Province dictionnary (1 country with "n" provinces...and 1 province with "n" regional divisions, like counties)? |
Not with this version, however, it may be something we add later down the line. It'd be more complicated to do since the "province" field would need to depend on the value from the "country" field, which we don't currently have an easy way to do without combining the fields, which is another can of worms 😅. |
Just gave this a go – works great! Love it <3 |
This pull request introduces the concept of Dictionaries to Statamic.
The Dictionary fieldtype works in a similar way to the Select fieldtype. However, the main difference is that the options are returned from a PHP class (called a "dictionary"), instead of being defined in the field's config.
There's a few common use cases where this is helpful:
Available Dictionaries
Statamic includes a few helpful dictionaries right out of the box:
Building your own dictionary
It's really easy to build your own dictionary...
Generate a dictionary class using
php please
:If you want to generate a dictionary for an addon, use the
--addon
parameter.In your
app/Dictionaries
directory (orsrc/Dictionaries
in an addon), you'll see your newProvinces
dictionary has been generated:options
method should return a key/value array of all options.$search
variable will be provided if the user is searching options. Feel free to search the options in whatever way works for you.get
method should return a single option.