hook_flag_options_alter() not working

sirkitree - November 4, 2009 - 15:30
Project:Flag
Version:6.x-2.0-beta1
Component:Flag core
Category:bug report
Priority:normal
Assigned:Unassigned
Status:closed
Description

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));
}
?>

#1

quicksketch - November 4, 2009 - 16:49

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

sirkitree - November 4, 2009 - 16:51

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

quicksketch - November 6, 2009 - 03:06
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

quicksketch - November 6, 2009 - 03:10
Version:6.x-2.x-dev» 6.x-2.0-beta1

#5

System Message - November 20, 2009 - 03:20
Status:fixed» closed

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

 
 

Drupal is a registered trademark of Dries Buytaert.