I've been hoping for an option like this for quite a while. thank you very much for making this availabe. However I'm not enough of a Drupal expert to get this working. Could you provide a simple code example (using the find_where_clause function)? so I can get a grip on this?

Comments

Alice Heaton’s picture

Status: Active » Fixed

Hi,

This is a module for development only, and you really shouldn't be using it unless you know what you are doing.

The only pointer I can give you is :

  1. In the filter, dump the $this object (eg. krumo($this) if you have krumo installed ; otherwise echo "<pre>";var_dump($this);echo "</pre>";)
  2. Preview the filter with the javascript disabled option (When building the filter you can go there directly at /admin/build/views/nojs/preview/<your_view_name>) - otherwise you'll get an error
  3. Study the data structure of the dumped object ; in particular the 'query' field

Once you've managed to write your own code to do what you like, I really advise you put it in your own module rather than use the Views Modify Query filter in a production site. You can use the Views Modify Query module as a squeleton, it's pretty simple.

Good luck !

ivrh’s picture

Wouldn't it be easier to write an example to use (you've spent at least 15 minutes typing this text above and what's point)? You still didn't answer the question asked. You mention everywhere - Don't use this module. What is the point of having it listed in Drupal then?

I am trying to figure out the syntax and what I came up so far is something like this:

global $user;
return $query['where'] = "node.nid IN ('". my_filter_nodes($user->uid) ."')";

where my_filter_nodes() is custom function that returns list of nodes for the current user in format 1,2,3,4 - but I can't find my statement in the mysql query listed in view preview box.

Please advise.
Thank you.

ivrh’s picture

Status: Fixed » Postponed (maintainer needs more info)

forgot to make active

Alice Heaton’s picture

Status: Postponed (maintainer needs more info) » Fixed

You mention everywhere - Don't use this module. What is the point of having it listed in Drupal then?

The point is to enable developers who already understand how the views module work to do some quick testing/hacks without having to write a whole module to do that. It is not there to help non-developers tweak their query.

The module description clearly states :

This is a module for advanced developers only ; only use it if you know what you are doing and understand the Views API.

I've removed this module from the listing of modules under 'Views' ; it's only under 'Developer' now so hopefully there will be less likelyhood of people getting confused in the future.

I'm sorry you're feeling frustrated about this, but I can't help you. Everything is said on the module page :

The code is run in the context of the 'query' call of a 'views_handler_filter' object ; so $this exists and represents the said object.

So to understand what you need to do, you need to understand how the views_handler_filter works. The views_handler_filter is an object that is part of the Views module ; so to understand that you need to look at the Views API documentation (which may or may not be complete at this time) or directly at the Views module.

Good luck :)

Anonymous’s picture

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for two weeks with no activity.