Entity reference select fields do not update properly

Created on 19 June 2023, about 1 year ago

Problem/Motivation

When using the module to update field data, not all changes are saved.

Steps to reproduce

  1. Create an entity reference field (such as a taxonomy term).
  2. Set the field to use autocomplete
  3. Create an entity reference field (such as a taxonomy term).
  4. Set the field to use a select list
  5. Bulk update field content for a node that uses those fields
  6. Change the values of both
  7. Only the autocomplete change is saved

Proposed resolution

Investigate how field data is processed -- likely the `target_id` of the widget.
Ensure proper handling of select fields.

Note that this may solve https://www.drupal.org/project/bulk_update_fields/issues/3363620 πŸ› Fields with Client-side Hierarchical Select widgets do not work Active and https://www.drupal.org/project/bulk_update_fields/issues/3185661 β†’ as well.

Remaining tasks

Find the problem
Fix the problem
Time permitting, write a test

User interface changes

None

API changes

None

Data model changes

None

πŸ› Bug report
Status

Needs review

Component

Code

Created by

πŸ‡ΊπŸ‡ΈUnited States agentrickard Georgia (US)

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

Comments & Activities

  • Issue created by @agentrickard
  • πŸ‡ΊπŸ‡ΈUnited States agentrickard Georgia (US)

    Here's the form data for the two types.

    Autocomplete:

    field_name
      widget
      0
      	target_id
      		value
    

    Select:

    field_name
      widget
        #key_column => target_id
        value	  		 
    
  • Status changed to Needs review about 1 year ago
  • πŸ‡ΊπŸ‡ΈUnited States agentrickard Georgia (US)

    I tracked this down to a mismatch in the default_value_input and form input values. (See attached screenshot).

    This patch fixed it for me, but I suspect there may be a better fix, perhaps in this part of `buildForm`:

                  else {
                    // TODO
                    // I cannot figure out how to get a form element for only a
                    // field. Maybe someone else can.
                    // TODO Doing it this way does not allow for feild labels on
                    // textarea widgets.
                    $form[$field_name] = $entity->get($field_name)->defaultValuesForm($temp_form_element, $temp_form_state);
                  }
    

    Other parts of this IF/ELSE set the field value, but know what widget they are targetting

    $form['default_value_input'][$field_name] = ....
    
Production build 0.69.0 2024