File Fields act strangely after step navigation

Created on 30 August 2023, over 1 year ago

Problem/Motivation

File fields display their weight dropdown and extra fields if they are rendered during step navigation.

If the file field is shown before entity_form_steps validateForm runs it will display as normal. Once the user navigates to a step, even the start step, the file field will look "broken". It's functionality is fine, the user can still upload files but the widget display is strange.

Steps to reproduce

  1. Create a form display with at least 2 steps
  2. Add a file upload field with unlimited granularity to any step.
  3. Navigate the form using the next/previous buttons.
  4. The file field will show it's weight dropdown and look strange.

Proposed resolution

I found that in the section of EntityFormSteps.php validateForm(), values that are not on the current step that get removed somehow has an affect on the file field.

    // Remove values not on the current step and build entity. Necessary to
    // support elements that are not using field widget plugins. Such as
    // custom fields added on the form build array.
    $values = $form_state->getValues();
    $keys = $form['actions']['submit']['#limit_validation_errors'];
    array_walk($keys, function (&$keys): void {
      $keys = current($keys);
    });
    foreach (array_keys($values) as $key) {
      if ($entity->hasField($key) && !in_array($key, $keys, TRUE)) {
        unset($values[$key]);
      }
    }

If I comment out line 318 unset($values[$key]);, the file fields do not exhibit the broken behavior. It seems that something gets lost here that the field wants but I'm not sure what.

πŸ› Bug report
Status

Closed: won't fix

Version

1.1

Component

Code

Created by

πŸ‡ΊπŸ‡ΈUnited States jimmynash

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

Comments & Activities

Production build 0.71.5 2024