Running on PHP 5.6 the following never gets called, however the same code running on PHP 7.1 results in the expected behaviour ( Ubuntu 16.04 with https://launchpad.net/~ondrej/+archive/ubuntu/php ).
<?php
use Drupal\views\ViewExecutable;
use Drupal\views\Plugin\views\query\QueryPluginBase;
function MODULE_views_query_alter(ViewExecutable $view, QueryPluginBase &$query)
{
die('test');
}
?>
Clearing the drupal cache or opcache doens not change/fix the situation.
Tested on a 8.4.2 standard install with a single custom module to implement the hook
Also confirmed on Ubuntu 14.04 LTS with standard distribution version of PHP 5.5.9
Comments
Comment #2
Makemeweb commentedComment #3
Makemeweb commentedComment #4
Makemeweb commentedComment #5
Makemeweb commentedComment #6
tetranz commentedI think the problem is the ampersand on &$query. I reproduced the problem when I blindly copied your code. I didn't notice the & at first. Then I copied from the API docs and now it works.
The & should not be there. It seldom makes sense to pass an object (handle) by reference.
Comment #7
Makemeweb commentedthank you, you are indeed correct, my code was not valid. Removing the & solves the issue and the hook is invoked correctly in PHP 5.6 and 7.1
Comment #8
Makemeweb commented