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

Makemeweb created an issue. See original summary.

Makemeweb’s picture

Issue summary: View changes
Makemeweb’s picture

Issue summary: View changes
Makemeweb’s picture

Status: Active » Needs review
Makemeweb’s picture

Status: Needs review » Active
tetranz’s picture

I 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.

Makemeweb’s picture

thank 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

Makemeweb’s picture

Status: Active » Closed (works as designed)