- Issue created by @krystalcode
- Merge request !7101Issue #3432276 Consider field item lists as equal if both are empty → (Open) created by krystalcode
I have come across cases where upon order refresh using Drupal Commerce, the price of the order is recalculated. When the order is saved, the total_price
field item list on the original entity does not contain any items, while the same field item list on the updated entity contains an item with an array with null
for both amount and currency as its value.
Both of these field item lists are considered as empty by the field API (isEmpty
method on FieldItemListInterface
) because the field type considers the field item in the updated entity as empty. However, the equals
method does not take into account the logic as isEmpty
and the result is that the two fields are considered not equal.
Regardless of whether the price on the updated entity should be set to an array with NULL values, that's something for Drupal Commerce. However, the fact that equals
considers as different two values that are considered both as empty by isEmpty
, I would consider it a bug in Drupal core.
1. Load an entity that does not have any field items in a given field.
2. Clone the entity.
3. In the cloned entity set the value of the field to contain an item that is not literally NULL but it is considered as an empty item by its field type.
4. Compare the two field item lists from the two entities using equals
.
5. Observe that the result is FALSE
.
Add a check on the equals
method to check if the fields are considered empty by the field type.
- Are there any caveats? Any reasons that, in general, we don't want this proposed behavior?
- Write a test.
Active
11.0 🔥