I'm reading through Pro Drupal development right now, and an example on page 82 uses the following function:
function menufun_menu_link_alter(&$item, $menu){
if ($item['link_path'] == 'logout'){
$item['link_title'] = 'Sign off';
}
}
I understand that I can find out what parameters "hook_menu_link_alter" takes by looking at api.drupal.org. What I don't understand is how I'm supposed to find out what $item actually contains. In this example, $item['link_path'] and $item['link_title'] were both used - how did he know they existed?
I'm not only interested in this specific example, of course. I want to be able to do this for any function that I look at in drupal.
Thanks in advance for the help!
If you went to api.drupal.org and looked up hook_menu_link_alter, you'd get this page:
http://api.drupal.org/api/function/hook_menu_link_alter/6
Which includes the following note:
"$item Associative array defining a menu link as passed into menu_link_save()."
If you follow the link to the menu_link_save page, you'd be here:
http://api.drupal.org/api/function/menu_link_save/6
In which the contents of the $item parameter is clearly listed under Parameters.
If you're using the Devel module I like to throw a
dsm($item)
in there to see what $item currently contains. It prints a nice interactive array/object navigator.
Granted you still have to go to the API to look up all the possibilities, since this only shows what's currently set. But it usually contains enough to get what I'm looking for.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With