Missing array key 'weight' on views created prior to 4.2.x-dev branch

Created on 23 May 2024, about 1 month ago
Updated 12 June 2024, 14 days ago

Problem/Motivation

After updating to the latest dev branch to bring in the awesome new feature ✨ Allow sorting of actions Needs work I found that I could no longer edit the VBO field on all of my old views. The following error would prevent the modal config in the view from opening:
Object { message: '\nAn AJAX HTTP error occurred.\nHTTP Result Code: 200\nDebugging information follows.\nPath: /en/admin/structure/views/ajax/handler/content/default/field/views_bulk_operations_bulk_form\nStatusText: parsererror\nResponseText: \nWarning: Undefined array key "weight" in /var/www/html/html/modules/contrib/views_bulk_operations/src/Plugin/views/field/ViewsBulkOperationsBulkForm.php on line 515

If I delete the VBO field and add a new one it works fine.

Steps to reproduce

1. On the most recent recommended branch of 4.2 create a view with a VBO field;
2. Update to the 4.2.x-dev branch
3. Edit the VBO field from #1
4. Open the browser console to see the error.

Proposed resolution

In the VBO field code modify the following code:

 513     uasort($this->actions, function ($a, $b) use ($selected_actions_data) {
 514       $weight_a = isset($selected_actions_data[$a['id']]) ? $selected_actions_data[$a['id']]['weight'] : 0;
 515       $weight_b = isset($selected_actions_data[$b['id']]) ? $selected_actions_data[$b['id']]['weight'] : 0;
 516       return $weight_a <=> $weight_b;
 517     });

to:

 513     uasort($this->actions, function ($a, $b) use ($selected_actions_data) {
 514       $weight_a = isset($selected_actions_data[$a['id']]['weight']) ? $selected_actions_data[$a['id']]['weight'] : 0;
 515       $weight_b = isset($selected_actions_data[$b['id']]['weight']) ? $selected_actions_data[$b['id']]['weight'] : 0;
 516       return $weight_a <=> $weight_b;
 517     });

Remaining tasks

User interface changes

API changes

Data model changes

πŸ› Bug report
Status

Fixed

Version

4.2

Component

Core

Created by

πŸ‡¨πŸ‡¦Canada joel_osc

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

Comments & Activities

Production build 0.69.0 2024