2

I'm trying to override some view by using the hook_views_pre_build hook. Following the documentation: https://api.drupal.org/api/drupal/core%21modules%21views%21views.api.php/function/hook_views_pre_build/8.1.x

My module is named "mymodule", I've got:

<?php
//... some code that works
// and my hook:
function mymodule_views_pre_build(&$view) {
   var_dump("hello"); die();
}

And that has no effect at all. Trying other hooks works, for example "mymodule_preprocess_page" is ok.

I do a "drush cr" each time, I tried other hook as "mymodule_views_pre_exec" that has no effect. It seems that Drupal 8.1 doesn't execute hook_views_XXX

Anyone can help me to resolve this ?

Metal3d
  • 2,905
  • 1
  • 23
  • 29

1 Answers1

3

First of all, the doc says:

hook_views_pre_build(ViewExecutable $view)

Try with ViewExecutable $view instead of &$view ?

Joel R
  • 81
  • 2
  • 1
    +1 to this: `call_user_func_array($function, $args)` seems to fail silently in D8 if the function's declared argument types aren't right. But you should also either `use Drupal\views\ViewExecutable;` at the top of the file, or specify the full namespaced class in the function declaration, as otherwise the class will resolve to `\ViewExecutable` and be incorrect. – J-P May 04 '17 at 17:03