This module provides a widget for entity reference fields that allows grouping checkbox or radio options into collapsible sections. These groupings can be based on fields within the referenced entities, enabling hierarchical organization of choices.
Overview
Group by Field Widget provides a Drupal entity-reference field widget that organizes selectable entities into collapsible groups.
Drupal’s standard entity-reference widgets display choices as a flat list. That can become difficult to navigate when a field contains many options or when those options naturally belong to categories, locations, departments, or other parent entities. This module uses fields on the referenced entities to build a more meaningful hierarchy.
Why use it?
This module is useful when:
- An entity-reference field contains too many choices for a flat list.
- Referenced entities already contain fields that describe how they should be grouped.
- Editors need contextual information to distinguish similarly named options.
Options belong to a hierarchy, such as campus → facility → display. - You want to improve form usability without changing how entity-reference values are stored.
The widget supports multiple grouping levels and can follow entity-reference relationships. This means grouping does not have to rely only on fields directly attached to the selectable entity.
Use case
Say you need to create a field that lists all the displays you have across all university campuses. So you create a 'Display' content type with a Field called facilities. A 'Facility' content type with field called campus. Lastly, a 'Campus' taxonomy vocabulary. With this module your displays field can be group by a number of nested fields. You can group by Facility or you can group by Campus which is an entity reference in your facility content type.
You typically would the options listed in a flat display like so.
├── Display 1
├── Display 2
├── Display 3
But what if those displays entities had their fields act as a grouping mechanic. A field referencing Displays could group its options by Facility and then by Campus:
Campus A
├── Facility One
│ ├── Display 1
│ └── Display 2
└── Facility Two
└── Display 3
Each group is rendered as a collapsible details section. Multi-value fields use checkboxes, while single-value fields use radio buttons. Optional radio selections can be cleared by clicking the selected option again.
Other common use cases
Typical applications include grouping:
- Locations by region or campus
- Employees by department
- Products by category
- Documents by organization
- Events by venue
- Equipment by facility
- Taxonomy terms or content by a related parent entity
The module changes only the form widget. Submitted selections remain standard Drupal entity-reference values, so existing storage, validation, and display behavior continues to work normally.
Installation/Configuration
- Add an entity reference field to node
- Head to manage form display, and change the widget to 'Group by field reference widget'
- If your field is multi-value, it will use checkboxes, otherwise it will use radios.
Related modules
- Grouped checkboxes: Allows you to group by taxonomy vocabularies.
- Entity Reference Tree Widget: Provides an entity relationship hierarchy tree widget for an entity reference field.
Troubleshooting
Empty "Group by" Selector.
This can happen for one of two reasons. First, only fields with a cardinality of 1 are allowed to be included in the list. Second, Fields using the "Views: Filter by an entity reference view" reference type must first select the bundles needed for field.
Features to come
- Nested grouping
- completed with 1.2.0 release
- Allow for nested fields with a cardinality of 1 to be included even if parent field isn't groupable
- Allow user to toggle whether the details elements should be open by default.
- completed with 1.2.0 release
- Allow users to select which hidden fields they would like to group by.
- Allow users to sort groupings.
- Allow for "Views: Filter by an entity reference view" taxonomy
- completed with 1.1.0 release
Depends on
Dependencies of the latest stable release
No dependencies recorded for this project.
Required by
Tracked projects that depend on this one
No tracked projects depend on this one yet.