field_updater_service
The easiest and fastest way to update fields in Drupal. Provides a batch processing service to copy values from one or more field sources to a target field.
Features
- Field mappings handled via configuration entities: entity_type, bundle, field_target, mappings
- Service to batch update field value based on configuration
- Can map to ANY field type from multiple field source values from the same entity.
- Supports custom default input and explicit NULL for values.
- Multi-lingual support.
- Reference fields (entity_reference & entity_reference_revisions) supported as a field mapping source.
- Eligible field mappings matched by target field schema.
Quick start
- Add a new field updater at /admin/config/field-updater
- Select: Entity type, Bundle, and Target field
- Select: Entity reference (if applicable) as the Field mappings source if you want to copy values from an entity_reference_revisions or entity_reference field type.
- Save the form and add mappings for the source.
- Copy content from Source to Target with
drush field-updater:update - Enter the number (#) of the field updater instance, and type "yes" when prompted.
- Copy example update hook from drush result to your own custom module's .install file for easy deployment to other environments.
Drush commands
drush field-updater:list - return a list of available updaters
drush field-updater:update - This drush command will prompt for available updater entities to select and provide example update hook upon completion of running the service.
Example Update Hook
/**
* Runs the FieldUpdaterService for the 'update_field_tags' config entity.
*/
function my_module_update_10001() {
// Get the FieldUpdaterService.
$updater_service = \Drupal::service('field_updater_service.updater');
$updater_service->updateEntities('update_field_tags');
}
Recommended modules/libraries
Custom Field - This module is an optimized alternative to paragraphs & blocks and field_updater module will provide the ability to copy existing values from other fields to this field type.
Similar projects
Bulk Update Fields - Designed to work with views as an action. Our module is simpler in scope and allows to define the mappings in separate configuration entities that can be run via update hooks and Drush commands by simply passing the config id as an argument.
Feeds - The feeds module provides functionality to import data from various sources to create new entities or update existing entities from data source based on a unique mapping id. The field_updater_service module will however fill the gap of being able to update fields from already existing values on the same entity and eliminate the need for complex update hooks to handle the batch processing.