Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Experimental project
This is a sandbox project, which contains experimental code for developer use only.
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
Related projects
Related issues
Supporting organizations:
Project information
- Minimally maintained
Maintainers monitor issues, but fast responses are not guaranteed. - Module categories: Developer Tools, Site Structure
- Created by ciss on , updated