Posted by sirkitree on November 4, 2009 at 3:30pm
| Project: | Flag |
| Version: | 6.x-2.0-beta1 |
| Component: | Flag core |
| Category: | bug report |
| Priority: | normal |
| Assigned: | Unassigned |
| Status: | closed (fixed) |
Issue Summary
Here's my symptoms.
In flag_abuse I'm trying to alter the default flag options. I can put a dsm() at the end of my hook implementation and I'm returned the expected alterations. But if I put:
drupal_alter('flag_options', $this, $options);
dsm($options);I am presented with the original $options array, completely unaltered.
Following is the code that should work:
<?php
/**
* Implementation of hook_flag_options_alter().
*/
function flag_abuse_flag_options_alter($flag, &$options) {
// $options['events'][] = 'reset'; //only able to do this after the flag_events patch...
$options += array(
'reset_short' => 'Reset flags',
'reset_long' => 'Reset all flags on this '. $flag->content_type,
'reset_message' => 'Flags reset.',
);
$options['roles'] += array('reset' => array(DRUPAL_AUTHENTICATED_RID));
}
?>
Comments
#1
Hmm, looks like we may have a problem with our call to drupal_alter(). Only the first parameter is ever passed by reference. If we swap the parameters and make it drupal_alter('flag_options', $options, $flag) it should work.
#2
There is also the option of using the special case: __drupal_alter_by_ref
@see http://api.drupal.org/api/function/drupal_alter/6
#3
Most of the time the pass-by-reference array is the first parameter, so I've swapped the arguments to match most other APIs in Drupal. Thanks for the report and research sirkitree!
#4
#5
Automatically closed -- issue fixed for 2 weeks with no activity.