Entity Extra Field

Allows site administrators to add various extra fields (blocks, views, tokens, twig templates, entity links, or components) to any entity display, supporting both form and view displays.

entity_extra_field
733 sites
59
drupal.org

概要

Entity Extra Fieldモジュールは、カスタムコードを書くことなくEntity表示に追加コンテンツを配置するための強力で柔軟な方法を提供します。サイト構築者は、Block、Views、Tokenベースのコンテンツ、Twigテンプレート、Entityリンク、またはSingle Directory Components(SDC)を任意のコンテンツEntityの追加フィールドとして配置できます。

これらの追加フィールドは、Entityビュー表示(訪問者向け)またはフォーム表示(編集者向け)で通常のフィールドと並べて配置できるため、Entityコンテキスト内に追加の動的コンテンツを表示する必要がある複雑なレイアウトに最適です。モジュールには包括的な条件システムが含まれており、特定の条件(ユーザーロール、現在のテーマ、リクエストパスなど)が満たされた場合にのみフィールドを表示できます。

各追加フィールドは設定Entityとして保存されるため、環境間でエクスポートおよびデプロイが可能です。モジュールはDrupalのPluginアーキテクチャに従っており、開発者は6つの組み込みタイプを超えて機能を拡張するためのカスタム追加フィールドタイプPluginを作成できます。

Features

  • Blockの設定とコンテキストに完全にアクセスしながら、BlockをEntity表示の追加フィールドとして追加
  • コンテキスト引数とTokenベースのオフセットをサポートして、Views表示を追加フィールドとしてレンダリング
  • テキストフォーマットをサポートした動的テキストコンテンツ用のTokenベースの追加フィールドを作成
  • Entityとグローバルなtwig変数にアクセスできるカスタムTwigテンプレートを追加フィールドとして記述
  • Entityリンク(canonical、edit-form、delete-formなど)を設定可能な追加フィールドとして追加
  • propとslotのマッピングを使用してSingle Directory Components(SDC)を追加フィールドとしてレンダリング
  • Drupalの条件Plugin(ユーザーロール、リクエストパス、現在のテーマなど)に基づく条件付き表示
  • Entityビュー表示とEntity編集フォーム表示の両方をサポート
  • 多言語サイト向けの設定翻訳を完全サポート
  • カスタム追加フィールドタイプを可能にする拡張可能なPluginアーキテクチャ
  • Field UIが有効な任意のEntityタイプ(Node、User、Taxonomy Term、Mediaなど)で動作
  • Entityタイプ、Bundle、フィールド名、ビューモードごとの詳細なテンプレートオーバーライド用のテーマ候補

Use Cases

Add page title as a field

Use the Token field type with [node:title] token to render the page title as a positionable field within the content area, allowing it to be placed between other fields instead of in the page template.

Embed related content view

Use the Views field type to embed a 'Related Articles' view that accepts the current node ID as a contextual filter argument using [node:nid] token, displaying related content within the node display.

Add contextual edit links

Use the Entity Link field type with 'edit-form' template to add an edit link that only appears for users with edit permission, positioned anywhere within the entity display.

Display custom block between fields

Use the Block field type to render a promotional banner or call-to-action block between specific content fields, rather than in a sidebar region.

Conditional author bio display

Create a Twig extra field that renders author biography information, with a User Role condition so it only appears for authenticated users or specific roles.

Render design system component

Use the Component field type to render an SDC card component, mapping the node title and summary to component props, ensuring consistent design across the site.

Add social sharing buttons

Use the Block field type to embed a social sharing block within the article content area, with Request Path conditions to only show on specific content paths.

Form-mode helper text

Create a Twig extra field on the Form display type to add instructional text or guidelines that appear within the entity edit form, helping editors understand field requirements.

Tips

  • The UI submodule can be disabled in production environments to reduce overhead, as extra field configurations are stored as config entities and don't require the UI to function
  • Use template suggestions (entity_extra_field__[type]__[bundle]__[field_name].html.twig) for field-specific styling without modifying the base template
  • Token replacement in Views arguments supports entity reference fields, allowing you to pass referenced entity IDs to contextual filters
  • Extra fields respect entity cache tags and contexts, ensuring proper cache invalidation when entities or configurations change
  • For complex Twig templates, consider implementing hook_entity_extra_field_twig_context_alter to add custom variables rather than putting all logic in the template
  • Block extra fields automatically receive the target entity as context, so context-aware blocks (like those using @entity_extra_field.target_entity) work correctly
  • Condition plugins are reusable - configure a condition once and it applies whenever that field is rendered, regardless of which display mode is used

Technical Details

Admin Pages 2
Manage extra fields /admin/structure/types/manage/{node_type}/extra-fields

Lists all extra fields configured for the entity bundle. Displays field label, field type, and display type (form or view) for each extra field. Provides operations to edit, delete, or translate each field. This page is dynamically available for any entity type with Field UI support (nodes, users, taxonomy terms, media, paragraphs, etc.).

Add extra field /admin/structure/types/manage/{node_type}/extra-fields/add

Form to create a new extra field for the entity bundle. Configure the field name, display type, field type, and type-specific settings. Additional condition settings control when the field appears.

権限 1
Administer entity extra field

Allows users to create, edit, delete, and translate extra field configurations for all entity types

Hooks 2
hook_entity_extra_field_twig_context_alter

Alter the Twig context variables available when rendering Twig-type extra fields. Allows modules to add custom variables to the Twig template context.

hook_extra_field_type_info_alter

Alter the extra field type plugin definitions discovered by the plugin manager

Troubleshooting 7
Extra field not appearing on entity display

After creating an extra field, navigate to 'Manage display' (for view fields) or 'Manage form display' (for form fields) and drag the new extra field from the Disabled section into the desired position in the display.

Changes to extra field not showing

Clear the Drupal cache after making changes to extra field configuration. The module caches field definitions for performance.

Block extra field shows nothing

Verify that the selected block has proper access permissions. Some blocks require specific contexts that may not be available on all entity displays.

Views extra field displays empty results

Check that the view has content and that contextual filters (arguments) are correctly configured. Use the token browser to ensure correct token syntax for arguments.

Twig template shows errors

The Twig template is validated on save. Ensure proper Twig syntax. Use {{ entity.field_name.value }} to access entity field values. Check the available context variables listed in the form.

Component field type not available

The Component field type requires the SDC (Single Directory Components) module. In Drupal 10.3+, SDC is included in core. For earlier versions, ensure the contrib SDC module is installed.

Conditions not working as expected

Check the 'All Conditions Must Pass' checkbox. When unchecked, the field displays if ANY condition passes. When checked, ALL conditions must pass. Test each condition individually.

Security Notes 4
  • The 'administer entity extra field' permission should only be granted to trusted administrators, as Twig templates can potentially expose sensitive information or cause performance issues
  • Block extra fields respect the underlying block's access control - if a user cannot access a block normally, they won't see it as an extra field
  • Token replacement uses Drupal's token system with clear=TRUE, which removes unreplaced tokens from output to prevent token syntax from being displayed to end users
  • Entity link extra fields respect entity access - links to edit or delete operations only render if the current user has permission for those operations