Skip to content

User network changes

Version v1

Initialising viewer…

You can apply this model as a recipe (Drupal 10.3 or later) to your own Drupal site:

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

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

# Apply recipe without Drush:
cd web && php core/scripts/drupal recipe ../recipes/eca_lib_0005

# Rebuilding caches is optional, sometimes required:
drush cr

Purpose

Users have references to a number of networks and when one gets added or deleted, this model recognizes the exact change and displays different messages about it.

For further reading, please go to this tutorial.

How the comparison works, and why the quotes matter

Both lists are encoded to JSON with "Tamper: encode", which produces the target IDs of the referenced terms rather than their names:

1
["7","8"]

Each item is then tested for membership with a contains comparison against that string. The needle is the term ID wrapped in the same double quotes JSON puts around every value:

1
"[loaded-term:id]"

The quotes are not decoration. Without them, looking for 4 would also match inside 14, and the model would report an item as already present when it is not. With them, "4" can only match a whole value, because JSON separates values with ",".

Two habits are worth taking from this:

  • Compare what the encoder actually emits. The list holds IDs, so the needle has to be an ID. A needle built from the term name can never match, and nothing reports the mismatch — every item simply reads as new, and the "already present" branch becomes unreachable.
  • Give the needle a boundary. Substring matching against a serialized list is only safe when the needle includes the delimiters the format guarantees.

Reading the messages

The four messages use [loaded-term:label] rather than [loaded-term:name]. Both look plausible, but only label is provided by ECA itself for every content entity; name on a taxonomy term depends on a token that may not be present, and resolves to an empty string when it is not. Each message also enables token replacement, without which the message would print the token literally.

Dependencies

  • config
    • field.field.user.user.field_user_networks
    • field.storage.user.field_user_networks
    • taxonomy.vocabulary.networks
  • module
    • eca_base
    • eca_content
    • eca_tamper
    • modeler_api
    • taxonomy
    • user

Used plugins

Events

Conditions

Actions