- Issue created by @xadler1
- 🇫🇷France lazzyvn paris
it's not a bug it's a feature. when a line is empty it will check and delete that line. Please note this module is written for the purpose of storing data and sub field is not like the fields you usually use.
- 🇨🇿Czech Republic xadler1
This seems strange to me to be a feature, maybe my example/explanation wasn't the best.
Simplest example is a datafield with entity reference and plain text fields (in this order). If I leave the entity reference empty and fill out the text field, the datafield will be saved correctly. But on next edit, the form will show an empty line even though there is data that could be edited.
The first example summarized into table:
Field definition from first example:
status: true dependencies: config: - field.storage.node.field_test_datafield_5 - node.type.test_type module: - datafield id: node.test_type.field_test_datafield_5 field_name: field_test_datafield_5 entity_type: node bundle: test_type label: 'TEST DATAFIELD 5' description: '' required: false translatable: false default_value: { } default_value_callback: '' settings: field_settings: text_1: label: Text_1 list: false allowed_values: '' required: false ref_1: label: Ref_1 required: false entity_reference_type: taxonomy_term target_bundles: islandora_models text_2: label: Text_2 list: false allowed_values: '' required: false field_type: data_field
- 🇨🇿Czech Republic xadler1
This seems strange to me to be a feature, maybe my example/explanation wasn't the best.
Simplest example is a datafield with entity reference and a text field (in this order). When the reference field is left empty and the text field is filled, the data is correctly saved. However, on next edit, this line is missing from the form, and after saving the data is overwritten.
A table for better ilustration of original example:
Datafield config:
langcode: en status: true dependencies: config: - field.storage.node.field_test_datafield_5 - node.type.test_type module: - datafield id: node.test_type.field_test_datafield_5 field_name: field_test_datafield_5 entity_type: node bundle: test_type label: 'TEST DATAFIELD 5' description: '' required: false translatable: false default_value: { } default_value_callback: '' settings: field_settings: text_1: label: Text_1 list: false allowed_values: '' required: false ref_1: label: Ref_1 required: false entity_reference_type: taxonomy_term target_bundles: islandora_models text_2: label: Text_2 list: false allowed_values: '' required: false field_type: data_field
PS: sorry for the later reply, I thought I posted the comment, but apparently that was not the case.
- 🇨🇿Czech Republic xadler1
I think I've found the issue. Method isEmpty()
https://git.drupalcode.org/project/datafield/-/blob/2.x/src/Plugin/Field/FieldType/DataFieldItem.php?ref_type=heads#L650
returns early when checking entity reference and file fields. Altering the if block to only return false when not empty fixes the issue. - 🇨🇿Czech Republic xadler1
Thank you and sorry for the delay. Now it works correctly.
Automatically closed - issue fixed for 2 weeks with no activity.