Problem/Motivation
The on change notifications in the entity and field APIs are not working properly because they are fired always by default when a field value is being set, even with the current value.
We have to ensure that at least the following use cases are covered and the expected behavior is defined:
$field->setValue($field->getValue()); - setting a field value with the current field value - no notification events should be fired.
Methods which are appending themselves to the notifications should be aware of modifying the field value and then it being reseted e.g.:
$original_value = $field->getValue();
$field->setValue('random');
$field->setValue($original_value);
One on change listener is being implemented in #2862574: Add ability to track an entity object's dirty fields (and see if it has changed).
Another challenge will be to cover changes on entity references where the notification has to bubble:
$entity_level_zero->ref_field->entity = $entity_level_one;
$entity_level_one->ref_field->entity = $entity_level_two;
$entity_level_zero->ref_field->entity->ref_field->entity->setTitle('random');
Identified issues
- #2862574: Add ability to track an entity object's dirty fields (and see if it has changed)
- #2988123: Appending/removing a field item to a field item list doesn't notify the parent of the change
- #2988126: Removing a field item from a field item list doesn't notify the parent of the change
- #2988174: Field's setValue method should not notify the parent of changes when being called multiple times with the same value
In this case a value has been changed on a entity at the third level of references and this change should bubble up to the entity at level zero.
Proposed resolution
Remaining tasks
After committing this un-postpone #2863844: Ensure that the changed field will update its value even if it is not the last field in pre save.
Comments
Comment #2
hchonovComment #3
hchonovComment #4
wim leersI'd prioritize this , because it hugely impacts what you can and cannot do with this API. It's super super super confusing right now. So confusing actually, that it's highly risky to implement anything with this API, because its semantics are ambiguous.
Comment #8
hchonovI've just identified one more issue - #2988123: Appending/removing a field item to a field item list doesn't notify the parent of the change - and already provided a test and a fix for that problem.
Comment #9
hchonovJust found one more and also provided a patch for it - #2988126: Removing a field item from a field item list doesn't notify the parent of the change. The test coverage in those last two issues lay the ground for testing the notification system.
Comment #10
hchonovComment #11
hchonovComment #21
acbramley commentedThis came up in today's BSI triage. I am not very familiar with this system but given the age of this issue, is this still present in 11.x?