Enumeration fields are not exactly relationships, but they implement a very similar scenario. Therefore, it's useful to know about them, so that you can use them when they are relevant.
Enumeration fields are fields that present a set of predefined values, of which one or several can be selected, depending on the field configuration. The values are defined per field, which means that those values can’t be re-used across different content parts. If you have a scenario for re-use of values, then you probably need to use a taxonomy instead.
To add an enumeration field, edit your content type definition and add a new field. If the “Fields” feature is enabled, you’ll be able to add an enumeration field:
Once the field has been added, we can expand its configuration and add values, one per line, in the “Options” text area:
Notice that you can specify whether a value is required, and what the UI will look like for the field, between a drop-down, radio buttons, checkboxes, or a select list. Which UI you choose will also determine whether multiple values will be accepted (radio and drop-down allow only for one value, while checkbox and select allow for multiple values).
In the content item editor for a song, we can now specify what formats the song is available under:
On the front-end, the values will be rendered as a label followed by the comma-separated list of values:
Of course, this rendering can be overridden with alternate templates in your theme. You could for example display those formats as nice SVG logos.
- No code.
- Complete tweakable admin UI for any cardinality.
- Simple implementation through the Infoset.
- As many enumerations as you want per content type.
- Can be queried against by projections.
- Not a chance of creating select n+1 performance bottlenecks with this.
- Not easy to query against, except using projections.
- Can't relate content items.
- No reusability of enumerations and their values.
You can use enumeration fields where a field is relevant, and where that field should have a discrete set of values that is not used for classification (use taxonomies for this). They are very lightweight, and also somewhat limited.