Field Cardinality
Component ID
2303057
Component name
Field Cardinality
Component type
module
Maintenance status
Development status
Component security advisory coverage
not-covered
Component created
Component changed
Component body
Sets a field form to a fixed amount of items and applies the Required status to all of them.
Warning: This is currently an API-only module, meaning it provides only utility functions without a configurable interface.
Problem
Multiple-valued field forms in Drupal have several limitations:
- Cardinality is set for the base field, meaning it can't be changed per field instance (this is to allow better handling by field storage backends).
- Only the first item will be validated as required. It is therefore not possible to have e.g. 4 required field items in a required field.
- Item offsets are very dynamic: if an item is considered empty, it will be removed and the next item will take its place (i.e. delta value).
This module attempts to tackle each point using the following strategies:
- Programmatically add additional item forms and add/set required values.
- Find elements marked as required on the first item and apply them to additional items.
- No real solution yet, since there is no way to mark a field as "not empty", intercept the removal or reliably determine which offsets got removed. Might require a mapping table and some magic.
Todos
- Reenable sorting
- Handle non-required fields (requires additional mapping table and a lot of magic)
- Provide field ui settings to:
- Set cardinality
- Provide per-delta labels and find reliable way to apply them
- Set required per delta?
- Provide field type to prevent field collections from being tested empty
- Better widget UI?
- Support for inline_entity_form? (very unlikely)
- Define behavior and add tests for:
- Core fields
- field_collection
- entity_translation
