Follow-up from #2226197: Introduce FieldStorageDefinitionInterface in the Entity Field API.
Problem
As discussed there at comment #30 and the following comments configurable field storage right now respects the field cardinality settings *during* the load()/save() operations. As I'd have expected that to influence validation only, this was quite a WTF to me.
Moreover this might result in data loss if:
- a field has e.g. 5 possible values and a node has 5 values
- the admin changes the field so that only 3 values are allowed.
- Now only the first 3 values are loaded and viewed, but the data remains.
- Now, a user edits the node and re-saves it - possibly even without even knowing/seeing our field with 3/5 values due to field access
- The node ends up being saved with only 3 values, the remaining two values are lost now
Proposal:
Respect field cardinality only during validation. Entity storage should store/load whatever is in the storage/entity.
Move the field cardinality setting to FieldDefinitionInterface as it does not influence storage at all - for the storage it's only important to know whether a field is multiple or not what would remain on StorageFieldDefinitionInterface (or whatever it ends up being called).
Comments
Comment #1
xjmThis would be a minor public API change, correct?
Comment #2
fagoyes, it results in the constant being moved away from FieldConfigInterface and the not yet existing StorageFieldDefinitionInterface.
Comment #3
tstoecklerI thought the constant should be on FieldDefinitionInterface per this issue? And only the multiple/not-multiple flag should be on StorageFieldDefinitionInterface? Still an API change, but...
Comment #4
fagoyes, by moving ot form FieldStorageDefinitionInterface to FieldDefinitionInterface, FieldConfigInterface stops inheriting it. So it results in being moved away from FieldConfigInterface. Imo, that's not a problem as all occurrences should be FieldDefinitionInterface::CARDINALITY_UNLIMITED then anyway.
Also, I'm unpostponing this as #2226197: Introduce FieldStorageDefinitionInterface in the Entity Field API got committed.
Comment #5
fago