I created a VBO action plugin which pass_view is true, after executing the action, it is broken and throws the following message. I also tested the views_bulk_operations_example action, there is the same problem on it.
Error: Call to a member function addMetaData() on string in Drupal\views\Plugin\views\query\Sql->execute() (line 1408 of XXX/core/modules/views/src/Plugin/views/query/Sql.php).
My Drupal core version is 8.4.2. The snippet of Sql.php is:
public function execute(ViewExecutable $view) {
$query = $view->build_info['query'];
$count_query = $view->build_info['count_query'];
$query->addMetaData('view', $view);
$count_query->addMetaData('view', $view);
Comments
Comment #2
johnhuang0808 commentedIn the patch, before executing the query, it should be build necessary info, otherwise, the query object is null.
Please take a look.
Comment #3
johnhuang0808 commentedComment #4
graber commentedI restructured the ViewsBulkOperationsActionProcessor class a bit in the last commit (f42efa5), it contains the setView() method that is called on initialization and includes
$this->view->build();instruction that should build the query under normal circumstances (there are some cases where the query isn't built, see public function ViewExecutable::build).Can you pull the latest dev and see if the problem persists?
If yes, it'd be good to provide steps to reproduce, as I couldn't with the last version.
Comment #5
joelpittetWe may want to run
pre_execute(), so that thosehook_views_pre_execute()hooks still fire, I've a related D7 patch in the queue.Comment #6
johnhuang0808 commentedHi @Graber, in the latest commit (f42efa5), the problem still exists in my development site.
But, I cannot reproduce it in a whole new Drupal site. I need some time to look for the root problem.
@joelpittet Could you share the issue link?
Comment #7
johnhuang0808 commentedComment #8
johnhuang0808 commentedAfter digging into the
ViewExecutale::build(), the problem is caused by the views' contextual filters without default value.Reproduce steps (Click to see the larger image):




1. Enable the views_bulk_operations_example module
2. Use the exiting content views in Drupal and create a new page display
3. Set the path (eg. /vbo_testing)
4. Add a user id context filter
5. Choose Show "Page not found"
6. Add a "Views bulk operations" views field
7. Select "VBO example action"
8. Save the views
9. Go to /vbo_testing/1
10. Perform the "VBO example action"
11. Receive an exception
Since the
ViewsBulkOperationsActionProcessor::setView()includes$this->view->build();, I tracedbuild()via XDebug to understand the behavior. I found$this->_buildArguments()inViewExecutalereturnsFALSE, so$this->query->build($this);never executed to build the necessary info.The snippet code of
ViewExecutale::build():Comment #9
johnhuang0808 commentedI removed the
if ($form_state->getValue('select_all'))condition inViewsBulkOperationsBulkForm::viewsFormSubmit(), the views argument and exposed input will pass into ViewsBulkOperationsActionProcessor. I have no idea why should user need to select all.Comment #10
graber commentedGood find @johnhuang0808!
Those values should be passed to the tempstore, regardless of the
select_alloption to build the view the proper way if it needs to be passed to the selected action object or used on a custom configuration / confirmation form.@joelpitet, yes, the way we currently execute the view query omits the
$module_handler->invokeAll('views_pre_execute', array($this));that is a part of standardViewExecutable::execute(). I'll check if we can change$this->view->query->execute($this->view);to$this->view->execute();inViewsBulkOperationsActionProcessor.To solve this issue, committing the #9 patch.
Thanks!
Comment #12
graber commentedI rushed a bit, those parameters should be populated and passed to the action processor even if there is no redirect route (no batching, confirmation or configuration), but in such a case we can just pass the entire view object instead of building it.
New patch attached, same effect but broader scope.
Comment #13
graber commentedForgot to actually include the view as an argument.
Comment #14
johnhuang0808 commented@Graber Thanks for the quick reply! The patch #13 works for me and looks great! Sorry, I ignored the no confirmation action in my patch #9.
I also tested on the actions with pass_view true and false.
Comment #16
graber commented