Multi-cardinality processed flag can have collisions

Created on 7 October 2024, 3 months ago

Problem/Motivation

In CustomWidgetBase.php we have formMultipleElements removing empty items from field state. This works find 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 on 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 bad 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'].

๐Ÿ› Bug report
Status

Active

Version

3.0

Component

Code

Created by

๐Ÿ‡บ๐Ÿ‡ธUnited States apmsooner

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

Production build 0.71.5 2024