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
Overview
The Entity Extra Field module provides a powerful and flexible way to add additional content to entity displays without writing custom code. It allows site builders to place blocks, views, token-based content, Twig templates, entity links, or Single Directory Components (SDC) as extra fields on any content entity.
These extra fields can be positioned alongside regular fields on entity view displays (for visitors) or form displays (for editors), making it ideal for complex layouts where additional dynamic content needs to appear within the entity context. The module includes a comprehensive condition system that allows fields to appear only when specific conditions are met (such as user roles, current theme, or request path).
Each extra field is stored as a configuration entity, making it exportable and deployable across environments. The module follows Drupal's plugin architecture, allowing developers to create custom extra field type plugins to extend functionality beyond the six built-in types.
Features
- Add blocks as extra fields on entity displays, with full access to block configuration and context
- Render Views displays as extra fields with support for contextual arguments and token-based offset
- Create token-based extra fields for dynamic text content with text format support
- Write custom Twig templates as extra fields with access to the entity and global Twig variables
- Add entity links (canonical, edit-form, delete-form, etc.) as configurable extra fields
- Render Single Directory Components (SDC) as extra fields with prop and slot mapping
- Conditional display based on Drupal's condition plugins (user role, request path, current theme, etc.)
- Support for both entity view displays and entity edit form displays
- Full configuration translation support for multilingual sites
- Extensible plugin architecture allowing custom extra field types
- Works with any entity type that has Field UI enabled (nodes, users, taxonomy terms, media, etc.)
- Theme suggestions for granular template override per entity type, bundle, field name, and view mode
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
/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.).
/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.
Permissions 1
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
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.
Clear the Drupal cache after making changes to extra field configuration. The module caches field definitions for performance.
Verify that the selected block has proper access permissions. Some blocks require specific contexts that may not be available on all entity displays.
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.
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.
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.
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