Reordering Weights causes order to be lost

Created on 16 April 2020, over 4 years ago
Updated 17 February 2023, almost 2 years ago

This code inside the multiple_fields_remove_button_submit_handler function causes the overall order of items to be lost and should be reworked.

(line 444 in multiple_fields_remove_button.module)

  if ($input && is_array($input)) {
    // Sort by weight.
    uasort($input, '_field_multiple_value_form_sort_helper');

    // Reweight everything in the correct order.
    $weight = -1 * $field_state['items_count'];
    foreach ($input as $key => $item) {
      if ($item) {
        $input[$key]['_weight'] = $weight++;
      }
    }
    NestedArray::setValue($formInputs, $address, $input);
    $form_state->setUserInput($formInputs);
  }

Removing it doesn't seem to cause a problem, the drag and drop functionality automatically reassigns assigns correct weights, and on saving the page the weights are also reordered to be correct without losing the user's original order.

πŸ› Bug report
Status

Active

Component

Code

Created by

πŸ‡ΊπŸ‡ΈUnited States electrokate

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

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.71.5 2024