Corresponding Entity References

CER keeps entity reference fields in sync by automatically creating and maintaining bidirectional references between entities.

cer
6,390 sites
75
drupal.org

Overview

Corresponding Entity References (CER) automatically maintains two-way relationships between entities that use entity reference fields. When entity Alice references entity Bob, CER automatically makes Bob back-reference Alice. This synchronization continues whenever either entity is created, updated, or deleted.

CER works through "presets" - configuration entities that define relationships between reference-type fields. You specify which two fields should correspond to each other and which entity bundles should participate in the relationship. The module integrates with any core Entity Reference field out of the box.

This module is the Drupal 8/9/10/11 successor to the Corresponding Node References (CNR) module, rebuilt from the ground up to work with any fieldable entity type, not just nodes.

Features

  • Automatic bidirectional synchronization of entity reference fields - when Entity A references Entity B, Entity B automatically references Entity A
  • Configuration entity-based presets for defining which fields should correspond to each other
  • Support for any entity type with entity reference fields (nodes, taxonomy terms, users, commerce products, etc.)
  • Bundle filtering to limit synchronization to specific entity bundles
  • Wildcard bundle support (entity_type:*) to include all bundles of an entity type
  • Add direction control - choose whether new references are prepended (added to top) or appended (added to bottom) of existing references
  • Enable/disable toggle for each corresponding reference preset
  • Manual synchronization capability for existing references through the admin UI
  • Automatic cleanup - when an entity is deleted, references to it are automatically removed from corresponding entities
  • Hook API (hook_cer_differences_alter) allowing other modules to modify synchronization behavior
  • Works with multi-value entity reference fields - handles adding and removing individual references correctly
  • Respects entity/field permissions - synchronization operates in normal security context

Use Cases

Bidirectional node relationships

Create two-way relationships between content types. For example, if you have 'Article' and 'Related Articles' where articles reference other articles, CER ensures that when Article A references Article B, Article B automatically shows Article A in its related articles field.

Author and authored content relationship

Link users to their content bidirectionally. If you have a custom 'Authored By' field on nodes and a 'Published Works' field on user profiles, CER keeps these synchronized automatically.

Product and category relationships

In e-commerce sites, maintain bidirectional relationships between products and categories. When a product is added to a category, the category automatically lists that product.

Event and speaker management

For event websites, link events to speakers and speakers to events. When a speaker is added to an event, that event automatically appears on the speaker's profile.

Organizational hierarchies

Create bidirectional parent-child or related-entity relationships within the same content type. Useful for organizational structures, location hierarchies, or any self-referencing relationships.

Cross-entity-type relationships

Link different entity types like nodes, taxonomy terms, and commerce products. For example, link blog posts to taxonomy terms and have terms automatically reference the posts tagged with them.

Tips

  • CER does not store any additional information about referenced entities, making upgrades from older versions straightforward - simply configure CER after upgrading and existing relationships continue working
  • Use the wildcard bundle option (entity_type:*) when you want all bundles of an entity type to participate in synchronization
  • The same field can be used for both First field and Second field to create self-referencing bidirectional relationships
  • Consider field cardinality when setting up presets - if a field only allows one reference, only the most recent reference will be kept
  • Use hook_cer_differences_alter() to add custom logic, such as only synchronizing published entities
  • Test corresponding references with a small set of content before applying to large content sets
  • Remember that CER respects entity and field permissions - test with appropriate user roles

Technical Details

Admin Pages 5
Corresponding references /admin/config/content/cer

Main administration page displaying a list of all configured corresponding reference presets. Shows each preset's label, machine name, corresponding fields, add direction (append/prepend), and enabled status. Provides operations links for editing, deleting, and synchronizing each preset.

Add corresponding reference /admin/config/content/cer/add

Form to create a new corresponding reference preset that defines a bidirectional relationship between two entity reference fields.

Edit corresponding reference /admin/config/content/cer/{corresponding_reference}

Form to modify an existing corresponding reference preset. All settings except the machine name can be changed.

Delete corresponding reference /admin/config/content/cer/{corresponding_reference}/delete

Confirmation form to permanently delete a corresponding reference preset. This does not remove any existing references from entities - it only removes the synchronization configuration.

Synchronize corresponding reference /admin/config/content/cer/{corresponding_reference}/sync

Confirmation form to manually trigger synchronization of all entities for this preset. Useful for bringing existing content into sync after creating a new preset or enabling synchronization.

Permissions 1
Administer Corresponding Entity References

Allows users to create, edit, delete, and synchronize corresponding reference presets. Users with this permission can manage all bidirectional entity reference configurations.

Hooks 1
hook_cer_differences_alter

Allows modules to alter the differences calculated by CER before they are applied. Called during entity synchronization to modify which references will be added or removed.

Troubleshooting 5
References are not being created automatically

Ensure the corresponding reference preset is enabled. Check that both entities being referenced belong to bundles configured in the preset's Bundles field. Verify that both entities have the configured reference fields.

Permission denied errors during synchronization

CER operates within normal security context. Ensure the current user has permission to edit the referenced entities. Check field-level permissions if using Field Permissions module.

Existing content not synchronized after creating preset

Use the Synchronize operation on the preset to process existing entities. Navigate to the preset's edit page and use the Synchronize task tab.

Self-referencing field not working

CER supports self-referencing relationships. Ensure both First field and Second field are set to the same field name, and that the bundles are correctly configured.

References appearing in wrong order

Check the Add Direction setting on your preset. Use 'Prepend' to add new references at the top or 'Append' to add them at the bottom of the reference list.

Security Notes 4
  • CER operates within normal Drupal security context - it cannot reference entities the current user cannot access
  • Users need the 'administer cer' permission to manage corresponding reference configurations
  • Synchronization operations respect entity access controls - unpermitted references will not be created
  • Be mindful of field-level permissions when using modules like Field Permissions alongside CER