Referenced Entity Replace
Replace references to one entity with another. Primary expected use case: to 'merge', or remove duplicate entities, updating every other entity that references the one to be removed the one being 'merged' into.
Features
The module's first audience is developers to use with drush having made a database backup.
It is active development but might also become suitable for developers to use as an API for creating a UI for 'merging' Taxonomy Terms or any other entities and updating all references to them.
- Find all fields that could reference an entity
- Update references on these fields with a batch operation
- Handle references in translations
Usage
Install as standard module. A drush command referenced_entity_replace should become available.
drush --help referenced_entity_replace
Update all references to an entity to another and remove.
Examples:
referenced_entity_replace taxonomy_term 5 6 Updates references to term 6 to 5 and removes
--batch-size=5 term 6.
Arguments:
entity_type_id Type of entity type.
new_entity_id The entity to reference.
old_entity_id The entity that is referenced to be removed.
Options:
--batch-size[=BATCH-SIZE] Number of entities to update per batch. [default: 10]
--no-delete-old Set if you don't want to remove the old entity.
The two classes included are: BatchReplace used by the Drupal command, but could be used for a Form batch, to create the batch, and run the operations updating all field values, and optionally removing the old entity; and ReplaceHelper available as the service referenced_entity_replace.helper which will return reference fields, and actually update entities.
Similar projects
For taxonomy term references, without batch operations:
For more entities, without batch operations, but with a UI:
Depends on
Dependencies of the latest stable release
No dependencies recorded for this project.
Required by
Tracked projects that depend on this one
No tracked projects depend on this one yet.
Activity
Releases
| Version | Type | Core | Release date | |
|---|---|---|---|---|
| 1.0.x-dev | Dev | Feb 4, 2024 | ||
| 1.0.0-alpha1 | Pre-release | Feb 4, 2024 |