Skip to content

Keep 2 fields in sync

Version v1

Instead of downloading the archive, you can download and apply this model as a recipe (Drupal 10.3 or later):

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
## Import recipe
composer require drupal-eca-recipe/eca_lib_0018

# Enable recipe with Drush (requires version 13 or later):
drush recipe ../recipes/eca_lib_0018

# Enable recipe without Drush:
cd web && php core/scripts/drupal recipe ../recipes/eca_lib_0018

# Rebuilding caches is optional, sometimes required:
drush cr

Purpose

This model demonstrates how a text field in a user entity can be kept in sync with a similar field in an associated profile entity. This works in both directions. Regardless which of the entities gets updated, the other one will be updated automatically as well.

Without paying attention, this could lead into an infinite loop. Therefore, the related entity only gets updated if the field values are not the same already.

The creation of that model has been recorded: Watch the video

Dependencies

  • config
    • field.field.profile.contact_detail.field_real_name
    • field.field.user.user.field_real_name
    • field.storage.profile.field_real_name
    • field.storage.user.field_real_name
    • profile.type.contact_detail
  • module
    • eca_base
    • eca_content
    • profile
    • user

Used plugins

Events

Conditions

Actions

Changelog

v1

Initial version