User network changes¶
Version v1
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 | |
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 | |
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 | |
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¶
- Update content entity (User: User)
- ECA custom event (entity-aware) (additions)
- ECA custom event (entity-aware) (deletions)
Conditions¶
Actions¶
- Load original version of user (unchanged)
- Show Message: no changes
- Serialize new networks
- Serialize orig networks
- Custom event: additions
- Custom event: deletions
- Load item provided by custom event
- Message: new item
- Message: item exists
- Message: deleted item
- Message: item remains
- Get field value: new networks
- Get field value: orig networks