1

I used this topic before asking question but even if the problem is very very closed, the answers given did not work for me.

So I need to alter the query of one of my views in drupal 7. I created a new module called for example 'mymodule'. This module contains

  • .info file.
  • .module file.
  • .views.inc file.

My .module file contains the following. Note that my .views.inc file is located at the root of the module directory. I also checked that my views api version is 3 :

function modulename_views_api() {
  return array(
    'api' => 3,
    'path' => drupal_get_path('module', 'modulename'),
  );
}

My .views.inc file, which is at the root of the module directory contains the following :

function modulename_views_query_alter(&$view, &$query) {
dpm($view);
watchdog('error title', 'error message');
echo 'TEST TEST';
die('test');
if ($view->name == 'my_view_name' && $view->current_display == 'my_display_name') {
    unset($query->where[1]['conditions'][0]);
    unset($query->where[1]['conditions'][1]);
 }
}

I can't see what I am missing trying to implement this hook but it never go into the views_query_alter function (I cleared the cache before trying). I think I've followed all advices given in the link provided above.

Any help would be appreciated.

4
  • Hmmmm maybe you need to clear cache in admin/config/development/performance Commented Jan 4, 2016 at 12:32
  • I already did it !
    – Samy-DT
    Commented Jan 4, 2016 at 13:28
  • Have you enabled the module? Code looks fine to me Commented Jan 4, 2016 at 14:52
  • You killed me, I "just" forget to enable the module...Sorry for the unuseful post, I'm still a beginner in Drupal and miss some basic reflex.
    – Samy-DT
    Commented Jan 5, 2016 at 10:34

1 Answer 1

0

.views.inc file is to separate the views alter logic.

hook_views_api to add the mymodule.views.inc file which can be with path your-module/includes/views or at the root of your module.

You also can use mymodule_views_query_alter at mymodule.module file which should work fine.

Please remove the cache after applying the changes.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.