I'm writing a module that should use hook_votingapi_storage_add_vote to run certain actions.
The problem is that the module (that is enabled and other hooks work) doesn't use the hook, here is the declaration:

/**
 * Implements of hook_votingapi_storage_add_vote().
 */
function edem_notifiche_votingapi_storage_add_vote(&$vote) {
  // Variable to get breakpoint
  $a = 1;
}

My module (edem_notifiche) works, my debugger works too and also other hooks on the same module.
What's wrong?

Thanks.

Comments

torotil’s picture

Category: bug » support
Status: Active » Fixed

hook_votingapi_storage*() are not hooks in the classical sense. Since there can be only one active implementation at a time there is a variable called votingapi_storage_module that indicates the module that handles the votingapi_storage.

In other words use variable_set('votingapi_storage_module', 'edem_notifiche'); or $conf['votingapi_storage_module'] = 'edem_notifiche'; and you should be fine.

arrubiu’s picture

Mh ok, as soon as possible I'll try it.
Two questions:
- is the function declaration right?
- does the function replace the "original" function or is a hook that performs his actions after the original function?

thanks

torotil’s picture

It replaces the original function. The declaration looks good.

arrubiu’s picture

It doesn't work.
On my module I've:

/**
 * Implements of hook_votingapi_storage_add_vote().
 */
function edem_notifiche_votingapi_storage_add_vote(&$vote) {
  drupal_write_record('votingapi_vote', $vote);
}

And this is the variable:

sdurzu@ubuntu:~/workspace/e-dem.local.dev$ drush vget votingapi_storage_module
votingapi_storage_module: "edem_notifiche"
sdurzu@ubuntu:~/workspace/e-dem.local.dev$

But I've a blank page and apache says:

[Mon Apr 08 08:54:46 2013] [error] [client 127.0.0.1] PHP Fatal error: Call to undefined function edem_notifiche_votingapi_storage_select_votes() in /home/sdurzu/workspace/subversion/e-dem/trunk/code/sites/all/modules/contrib/votingapi/votingapi.module on line 363

Have I to replace EVERY function declared in the votingapi.api.php^

torotil’s picture

Exactly. The storage module needs to take care of ALL storage functions.

arrubiu’s picture

Mhh, I'll try Rules integration, if it works.
Let me say that this use of hooks is a bit ambiguos, compared with the default implementation of hooks and maybe it should be explained in a better way.

If Rules's integration doesn't work I'll try to redeclare every function.

Thanks!

torotil’s picture

Yeah. In 3.x The storage will be an class so you can inherit the default implementation. Sorry for the complications I've inherited that architecture (I've only been maintainer since last autumn).

In the meanwhile you could also add dummy/proxy functions in your module so you don't need to c&p the default implementation.

arrubiu’s picture

However the Rules - VotingAPI module (http://drupal.org/project/voting_rules) seems works.

Status: Fixed » Closed (fixed)

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

shailu29’s picture

documentation here: https://drupal.org/node/68877) is correctly triggered.