Entity Group Field
Provides a computed field to view and manage group associations directly on entity forms and displays.
entitygroupfield
Overview
Entity Group Field is a module that provides a computed field which can be configured on any entity types associated with the Group module. This allows users with sufficient permissions to view group associations directly while viewing entities, and to manage group associations while editing entities.
The module automatically detects which entities can belong to groups based on installed Group relation type plugins (like gnode for nodes). It provides two widget options for managing associations (select dropdown and autocomplete) and four formatter options for displaying group information. The module respects Group's permission system, only showing groups the current user has permission to add content to.
Common use cases include managing which groups a node belongs to from the node edit form, or managing user group memberships directly from the user profile form.
Features
- Computed field that automatically discovers and displays group relationships for any entity type with Group relation plugins enabled
- Select widget providing a dropdown organized by group type with optgroups, showing only groups the user has permission to add content to
- Autocomplete widget for sites with large numbers of groups, providing type-ahead search functionality with permission filtering
- Parent group label formatter displaying group names with optional linking to the group page
- Parent group rendered entity formatter allowing groups to be displayed using any configured view mode
- Parent group ID formatter showing the numeric group identifier
- AJAX-powered interface for adding and removing group associations without page reloads
- Dropbutton interface with Edit, Remove, Collapse, and Restore operations for managing existing group relationships
- Support for both Group 2.x (group_content) and Group 3.x (group_relationship) entity types
- Permission-aware validation ensuring users can only add content to groups they have appropriate access to
- Configurable widget settings including multiple values, required field validation, custom labels, and help text
- Automatic cleanup of field configuration on module uninstall
Use Cases
Managing node group assignments from the node edit form
Enable the 'Groups' field on the node form display (e.g., /admin/structure/types/manage/article/form-display) using either the select or autocomplete widget. Content editors can then add nodes to groups while creating or editing content, without navigating to the group administration pages.
Managing user group memberships from user profiles
Enable the 'Group memberships' field on the user form display (/admin/config/people/accounts/form-display). Administrators can then manage which groups a user belongs to directly from the user edit form, streamlining user management workflows.
Displaying group affiliations on content pages
Enable the 'Groups' field on content view displays using the 'Parent group label' formatter with linking enabled. Visitors can see which groups content belongs to and click through to the group pages, improving content discovery and navigation.
Showing group information with custom styling
Use the 'Parent group rendered entity' formatter with a custom view mode to display rich group information (like group logos or descriptions) alongside content, providing more context about the content's organizational affiliation.
Tips
- The computed field uses different default labels: 'Group memberships' for user entities and 'Groups' for all other entities. Use the Base Field Override UI module to customize these labels.
- The select widget organizes groups by group type using HTML optgroups, making it easier to find specific groups on sites with multiple group types.
- When a user lacks permission to add content to any groups, the widget will display 'Not yet added to groups' with no add button - this is expected behavior based on Group permissions.
- The autocomplete widget performs permission validation during form submission, preventing users from adding content to groups they don't have access to even if they manually enter a group ID.
- Both widgets support drag-and-drop reordering of group associations when the 'multiple' setting is enabled.
- Group associations are saved during entity save, not immediately when adding via the widget - unsaved changes show a warning message when collapsed.
Technical Details
Hooks 4
hook_entity_base_field_info
Adds the computed 'entitygroupfield' base field to all entity types that have Group relation plugins enabled. The field is automatically named 'Group memberships' for user entities and 'Groups' for all other entity types.
hook_theme
Defines the 'entitygroupfield_dropbutton_wrapper' theme hook used for rendering operation buttons in the widget.
hook_field_formatter_info_alter
Adds 'entitygroupfield' to the field types supported by the core 'entity_reference_entity_view' formatter, enabling the 'Rendered entity' formatter option.
hook_uninstall
Cleans up by removing the entitygroupfield component from all entity form and view display configurations when the module is uninstalled.