views:

614

answers:

3

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!

+6  A: 

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.

Amber
+4  A: 

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.

AK
A: 

Using the API docs or displaying variables is both good tools to get info. They both have their merits, using devel is mostly useful when you are debugging and want to see what is happening. A big part of being a good drupal developer is not knowing everything, but more being able to track down the relevant info. Sometimes it can also bevery useful to look at the code or code by others. Seeing how others do things can sometimes help out a lot when you want to do something similar. Google can also be a good tool or discussing an issue with some one. There are many posibilities, you just have to learn how to use these tools and use what works for you. After spending more time at api.drupal.org you do get better to extract infomation.

googletorp