Entity Group Field

Provides a computed field to view and manage group associations directly on entity forms and displays.

entitygroupfield
2,828 sites
41
drupal.org

概要

Entity Group Field は、Group モジュールに関連付けられた任意の Entity タイプに設定できる computed field を提供するモジュールです。十分な権限を持つユーザーは、Entity を閲覧しながらグループの関連付けを直接確認したり、Entity の編集中にグループの関連付けを管理したりできます。

このモジュールは、インストールされている Group relation type plugin(Node 用の gnode など)に基づいて、どの Entity がグループに所属できるかを自動的に検出します。関連付けを管理するための2つのウィジェットオプション(select ドロップダウンとオートコンプリート)と、グループ情報を表示するための4つのフォーマッターオプションを提供します。モジュールは Group の権限システムを尊重し、現在のユーザーがコンテンツを追加する権限を持つグループのみを表示します。

一般的なユースケースには、Node 編集フォームから Node が所属するグループを管理したり、ユーザープロフィールフォームからユーザーのグループメンバーシップを直接管理したりすることが含まれます。

Features

  • Group relation plugin が有効な任意の Entity タイプのグループ関係を自動的に検出・表示する computed field
  • optgroups でグループタイプ別に整理されたドロップダウンを提供し、ユーザーがコンテンツを追加する権限を持つグループのみを表示する select ウィジェット
  • 多数のグループを持つサイト向けに、権限フィルタリング付きの先行入力検索機能を提供するオートコンプリートウィジェット
  • グループページへのリンクをオプションで設定できる、グループ名を表示する親グループラベルフォーマッター
  • 設定された任意の view mode でグループを表示できる親グループ rendered entity フォーマッター
  • 数値のグループ識別子を表示する親グループ ID フォーマッター
  • ページリロードなしでグループの関連付けを追加・削除できる AJAX 対応インターフェース
  • 既存のグループ関係を管理するための Edit、Remove、Collapse、Restore 操作を備えた Dropbutton インターフェース
  • Group 2.x(group_content)と Group 3.x(group_relationship)の両方の Entity タイプをサポート
  • ユーザーが適切なアクセス権を持つグループにのみコンテンツを追加できることを保証する権限認識型バリデーション
  • 複数値、必須フィールドバリデーション、カスタムラベル、ヘルプテキストなどの設定可能なウィジェット設定
  • モジュールアンインストール時のフィールド設定の自動クリーンアップ

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.