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.

  • Hmmmm maybe you need to clear cache in admin/config/development/performance – Gianni Di Falco Jan 4 '16 at 12:32
  • I already did it ! – Samy-DT Jan 4 '16 at 13:28
  • Have you enabled the module? Code looks fine to me – Gianni Di Falco Jan 4 '16 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 Jan 5 '16 at 10:34
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, privacy policy and cookie policy

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