Problem/Motivation
In CustomWidgetBase.php we have formMultipleElements removing empty default item from field state. This works fine outside of when a custom_field is attached to a multi-valued paragraphs field. The latter scenario seems to result in the removal of the only item on paragraphs form ajax updates which leads to loss of data in the first item. It's particularly noticeably broken when one of the sub-fields is of type entity_reference with target_type media and using the media library widget but other field structures result in same undesirable behavior.
Steps to reproduce
Add a multi-valued custom_field to a paragraph type. Add a multi-value paragraph field to a node containing that type. Add a node and add a paragraph, then add a second paragraph and notice the first one's custom_field values are not preserved.
Proposed resolution
1. Set a more unique $processed_flag variable in formMultipleElements to contain the parents.
2. Add a condition to check for empty($field_state['array_parents']) before decrementing $field_state['items_count'].
Issue fork custom_field-3479254
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #3
apmsooner commentedComment #4
apmsooner commentedComment #8
apmsooner commentedComment #9
apmsooner commented