Bulk form field disappears after using AJAX

Created on 9 February 2024, 7 months ago
Updated 27 August 2024, 12 days ago

Problem/Motivation

This is not reproducible with Views Bulk Operations out-of-the-box on a simple page using VBO. So it's possible I'm posting the problem/solution in the wrong place.

The changes in πŸ“Œ Create API for view provider modules to provide entity labels and bulk form keys Fixed introduced a regression on our site where Views that had AJAX enabled would lose their VBO form after any AJAX callback (i.e. submitting an exposed filter).

In our case, the problem is because we have other code instantiating a Views display handler that also happens to use VBO and it causes a conflict over the ViewsBulkOperationsViewData service.

During the AJAX callback...
1. The display handler for the current page is initialized, setting the $view reference in ViewsBulkOperationsViewData
2. Before the view is rendered, a separate (or just a new instance) of a display handler is instantiated which reinitializes ViewsBulkOperationsViewData with a new $view reference.
3. The original view is now rendered, but when ViewsBulkOperationsBulkForm::viewsForm attempts to getViewEntityData it does so for the wrong $view.

Steps to reproduce

1. Apply patch 46 πŸ› Views argument validators aren't taken into account on access checks - local task point to 404 Needs work from πŸ› Views argument validators aren't taken into account on access checks - local task point to 404 Needs work .
2. Create a view with a page and a Views Bulk Operation form
3. Enable AJAX on the view
4. Create an exposed filter (i.e. for the entity name)
5. Save the view and go to the page
6. Submit the form for the exposed filter (you don't need to enter anything into the form).

When the page first loaded, the bulk operation checkboxes were there. After any AJAX callback, the bulk operation checkboxes will disappear.

Proposed resolution

Although the steps to replicate reference a patch that is not in core--I expect this issue could manifest in other ways. I think it is probably a fundamental risk of having plugin instances attempt to use a shared references to a single ViewsBulkOperationsViewData service.

For now, simply re-initializing the ViewsBulkOperationsViewData service right before rendering the bulk form works.

πŸ› Bug report
Status

Needs review

Version

4.2

Component

Core

Created by

πŸ‡ΊπŸ‡ΈUnited States mediabounds

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

Comments & Activities

Production build 0.71.5 2024