- 🇪🇸Spain grota
I think this is the way to reproduce it:
- create a view using a table style plugin.
- add some fields: at least a vbo field, configured to use batch, and a date field, used for the next point.
- configure the table style plugin to use a date field as default sorting option.This should be enough.
The problem is in
ViewsBulkOperationsActionProcessor::getPageList
.
The workaround from 3020922 → is nullified when it calls$this->view->build();
since it calls$this->style_plugin->buildSortPost()
which in our case is inDrupal\views\Plugin\views\style\Table::buildSortPost()
which in turn ends up callingDrupal\views\Plugin\views\field\EntityField->clickSort()
which sets the order by statement based on the table's default sorting field.I don't know what a proper fix should be, but I hope the previous description can be useful to find one.
I have put the following workaround in place based on
hook_views_query_alter
:
As a note, I also tried an approach based onhook_views_pre_execute
without success (probably because the query was already built).use Drupal\views\Plugin\views\query\Sql; /** * Whether the view is configured in batch mode. */ function xxx_vbo_view_is_vbo_configured_in_batch_mode(ViewExecutable $view) : bool { $fieldHandlers = $view->getHandlers('field'); foreach ($fieldHandlers as $fieldHandler) { if (($fieldHandler['plugin_id'] ?? NULL) === 'views_bulk_operations_bulk_form') { return $fieldHandler['batch'] ?? FALSE; } } return FALSE; } /** * Get base field alias for a view. * * Algorithm copied from * \Drupal\views_bulk_operations\Service\ViewsBulkOperationsActionProcessor::populateQueue. */ function xxx_get_view_base_field_alias(ViewExecutable $view) : string { $base_field = $view->storage->get('base_field'); if (isset($view->query->fields[$base_field])) { if (!empty($view->query->fields[$base_field]['table'])) { $base_field_alias = $view->query->fields[$base_field]['table'] . '.' . $view->query->fields[$base_field]['alias']; } else { $base_field_alias = $view->query->fields[$base_field]['alias']; } } else { $base_field_alias = $base_field; } return $base_field_alias; } /** * Implements hook_views_query_alter(). */ function xxx_views_query_alter(ViewExecutable $view, QueryPluginBase $query) { // Operate only on views currently run by VBO. if (!isset($view->views_bulk_operations_processor_built)) { return; } // Operate only on VBOs that are configured in batch mode. if (!xxx_vbo_view_is_vbo_configured_in_batch_mode($view)) { return; } if (!$query instanceof Sql) { return; } $base_field_alias = xxx_get_view_base_field_alias($view); $query->orderby = [ [ 'field' => $base_field_alias, 'direction' => 'ASC', ], ]; }
- 🇵🇱Poland Graber
Hmm, can you try setting style plugin to
default
just before$this->view->build();
in the action processor?
$this->view->setHandler($this->bulkFormData['display_id'], 'style', 'default', []);
(not sure about the last argument..). - 🇵🇱Poland Graber
ok, more like
$this->view->style_plugin = Views::pluginManager('style')->createInstance('default');
The plugin needs to be initialized as well though.. - 🇪🇸Spain grota
Hi @Graber, sorry for the delay in answering. My proposed fix above had to be reverted because it actually introduced other regressions (incorrect elements on which ultimately the action is executed on) while selecting items across pages.
As soon as we'll be able to have another go at fixing the problem I'll let you know. - last update
over 1 year ago 15 pass - @grota opened merge request.
- Status changed to Needs review
over 1 year ago 8:58am 8 August 2023 - 🇪🇸Spain grota
Hi @Graber,
I saw that you added those 2 lines in 22d6240fd295ec59bb758e8279046507fbbc528b. I tested them and they fixed the issue for me.
I created this MR to add a test.As far as I know there are no other scenarios right now where the set of selected rows is incorrect, so for me this issue can be closed.
- last update
over 1 year ago 15 pass - Status changed to Fixed
over 1 year ago 9:48am 16 August 2023 - 🇵🇱Poland Graber
TBH.. I accidentally added those lines in that commit, that should've been tested.. Oh well, I'm glad it worked and thank you for the test coverage!
Automatically closed - issue fixed for 2 weeks with no activity.