Field Inheritance

Provides the ability to inherit field data from one entity to another using computed fields and configurable inheritance strategies.

field_inheritance
1,308 sites
32
drupal.org

Install

Drupal 11, 10 v3.0.1
composer require 'drupal/field_inheritance:^3.0'
Drupal 9, 8 v2.0.0
composer require 'drupal/field_inheritance:^2.0'

Overview

Field Inheritance is a powerful module that enables site administrators to inherit any field from any entity into any other entity. It can be considered a field-level entity reference alternative, where instead of referencing entire entities, you can pull in specific field values from source entities to destination entities.

The module creates computed fields on destination entities that dynamically retrieve and display data from source entities. This approach is particularly useful for scenarios where you need to share common data across different content types without duplicating the data or creating complex entity relationships.

The module supports four inheritance strategies: Inherit (pull field data directly from the source), Prepend (place destination data above source data), Append (place destination data below source data), and Fallback (show destination data if set, otherwise show source data). It provides a plugin system that allows developers to extend the inheritance functionality for specific field types.

Features

  • Create computed fields that inherit data from source entities to destination entities dynamically
  • Four flexible inheritance strategies: Inherit, Prepend, Append, and Fallback for different use cases
  • Support for all fieldable entity types including nodes, taxonomy terms, users, block content, and custom entities
  • Plugin-based architecture for handling different field types (Default plugin for any field type, Entity Reference plugin for entity references, images, files, paragraphs, webforms)
  • Entity-level and field-level mapping controls to specify which source entity provides data for each inherited field
  • Views integration to display inherited field data in views
  • Token integration for using inherited field values in tokens
  • Configuration entity system allowing import/export of inheritance rules
  • Widget for content editors to enable/disable inheritance and select source entities per content item
  • Translatable content support with language fallback for inherited data
  • Base field added to enabled entity types for storing inheritance configuration per entity

Use Cases

Inheriting taxonomy terms from parent content

A website has 'Category' nodes with taxonomy term fields. Child 'Article' nodes can inherit the category terms from their parent Category, ensuring articles are automatically tagged with the same terms as their category without manual selection.

Sharing header images across related content

A 'Campaign' content type has a hero image field. Related 'Event' nodes can inherit this hero image, providing visual consistency across campaign materials. Using the 'fallback' strategy, individual events can override with custom images when needed.

Cascading author information

A 'Series' content type has detailed author information. Individual 'Episode' nodes can inherit author fields from the Series using the 'inherit' strategy, eliminating data duplication while maintaining consistent author attribution.

Combining body content from multiple sources

Using 'prepend' or 'append' strategies, combine body content from a template entity with content-specific text. For example, a disclaimer from a 'Template' node can be automatically appended to all 'Legal Document' nodes.

Product variation inheriting base product data

An e-commerce site has 'Product' nodes with common descriptions. Product 'Variation' nodes inherit the base description while adding variation-specific details using the 'prepend' or 'append' strategy.

Tips

  • Use Entity Mappings for simpler configurations where all inherited fields come from the same source entity, and Field Mappings when different fields need different source entities
  • The 'fallback' strategy is particularly useful for providing default values that can be overridden on individual entities
  • Inherited fields can be displayed in Views, allowing you to build listings that include inherited data
  • When creating inheritance rules for entity reference fields (including images, files, paragraphs), the module automatically selects the Entity Reference Field Inheritance plugin for proper handling
  • The field_inheritance base field is revisionable, meaning inheritance settings are tracked per revision when the destination entity type supports revisions
  • Export field inheritance configuration using config export for deployment across environments

Technical Details

Admin Pages 7
Field Inheritance /admin/structure/field_inheritance

Main administration page for Field Inheritance module. Provides access to the list of configured field inheritances and module settings.

Settings /admin/structure/field_inheritance/settings

Configure global settings for the Field Inheritance module, including which entity types can use field inheritance.

Confirm entity removal /admin/structure/field_inheritance/settings/confirm

Confirmation page displayed when removing entity types from field inheritance. Warns that all Field Inheritance data from the removed entity types will be lost.

Field Inheritance /admin/structure/field_inheritance/list

Lists all configured field inheritance rules showing label, machine name, type (inheritance strategy), source entity/bundle, source field, destination entity/bundle, and destination field.

Add Field inheritance /admin/structure/field_inheritance/add

Form to create a new field inheritance rule, defining how field data is inherited from a source entity to a destination entity.

Edit Field inheritance /admin/structure/field_inheritance/{field_inheritance}/edit

Form to edit an existing field inheritance rule. All fields except machine name can be modified.

Delete Field inheritance /admin/structure/field_inheritance/{field_inheritance}/delete

Confirmation page for deleting a field inheritance rule. The computed field will be removed from the destination bundle.

Permissions 1
Administer Field Inheritance configuration

Allow access to the administration form to configure Field Inheritance. This is a restricted permission.

Hooks 3
hook_field_inheritance_inheritance_class_alter

Allows altering the inheritance class used to build the inherited base field. Use this to provide custom factory classes for specific inheritance plugins.

hook_field_inheritance_compute_value_alter

Allows altering the computed value for an inherited field. Use this to modify inherited data before it is returned.

hook_field_inheritance_info_alter

Allows altering the discovered field inheritance plugin definitions.

Troubleshooting 5
Inherited field not appearing on entity

Ensure the Field Inheritance widget is enabled on the entity form display and the 'Enable inheritance for this entity' checkbox is checked. Also verify a source entity is selected in the Field Mappings or Entity Mappings section.

Source and destination field types must match error

When using prepend, append, or fallback strategies, the source and destination fields must be of the same type. Ensure you've selected compatible fields.

Computed field not showing inherited data

Check that: 1) The destination bundle has a 'field_inheritance' field configured, 2) The entity has inheritance enabled, 3) A valid source entity is selected, 4) The source entity has data in the source field.

Entity type not available in settings

Only fieldable entity types appear in the Settings page. Custom entity types must implement FieldableEntityInterface.

Changes to inherited data not appearing

Inherited fields are computed at render time. Clear caches if changes to inheritance configuration aren't reflected. Changes to source entity data should appear immediately without cache clearing.

Security Notes 3
  • The 'administer field inheritance' permission is marked as restricted access - only grant to trusted administrators
  • Field inheritance respects entity access - users can only inherit from entities they have access to view
  • When inheriting sensitive field data, ensure appropriate view permissions are in place on both source and destination entities