Download & Extend

hook_flag_options_alter() not working

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

Status:active» fixed

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!

AttachmentSize
flag_options_alter_fix.patch 590 bytes

#4

Version:6.x-2.x-dev» 6.x-2.0-beta1

#5

Status:fixed» closed (fixed)

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

nobody click here