I’m getting no love from hook_query_alter. I have a simple query to which I want to add a tag, while also adding a node_access
tag. Thus the whole query looks like this:
$the_nodes = db_select('node', 'n') ->condition('n.type', 'some_node_type') ->fields('n', array('nid', 'title')) ->addTag('node_access') ->addTag('my_custom_tag') ->execute()->fetchAll();
I then define a handler in one of my modules and litter it with debugging statements, hoping something will happen:
function mymodule_query_alter(QueryAlterableInterface $the_query) { dsm("inside mymodule_query_alter"); dsm($the_query); if ($the_query->hasTag('my_custom_tag')) { dsm('Found it!'); // do real work here } }
I then clear the system cache. Once I’ve done this, the following things happen:
- My handler is running, and reports a number of invocations from various system calls.
- The objects being dumped by the dsm calls are all very much alike — they contain only an
alterTags
array, which typically has entries for eithernode_load_multiple
orfile_load_multiple
, but nothing else — certainly nothing like a full Query object. - None of the
alterTags
arrays have an entry formy_custom_tag
. - The inner “Found it!” message never fires.
Arggh. This is my first encounter with hook_query_alter()
, and I’m probably just missing something basic about its use. Can anybody clue me in? (BTW, based on some browsing around, I’ve also tried defining handlers for my_module_query_my_custom_tag_alter
and my_module_query_node_access_alter
, but never see anything from them.)
Sponsored by SupremePR