I needed the ability to allow modules to add/remove badges. Please find attached a small patch that adds a new "hook_user_badges" that modules may implement to modify the user's badges.
Note that this does not use module_invoke_all, as the first argument must be passed by reference. It uses instead the same method used by user_module_invoke">.
Example use by a module:
/* Implementation of hook_user_badges */
function goopackage_user_badges(&$badges, $uid)
{
if ($uid == 3) {
$badges[2] = user_badges_get_badge(2);
}
}
| Comment | File | Size | Author |
|---|---|---|---|
| user_badges_hook.patch.txt | 664 bytes | davidc |
Comments
Comment #1
Richard Blackborder commentedI think drupal_alter() will let you achieve want you want here without hard coding a hook invoking system.
Thanks for the patch!
I'm going to move this onto 6.x or else I'll keep missing it.
Comment #2
nancydruNo update in a year. If you try drupal_alter, please let us know if it works, and maybe a piece of sample code.