Proper use of hook_menu_breadcrumb_alter() I have a situation where I need to mess with a breadcrumb on a page and insert some items in the middle.  In my instance drupal_set_breadcrumb() can't be used, so I need to implement a hook_menu_breadcrumb_alter().  I am a little confused about proper usage with this, though, and am not terribly familiar with the guts of how the menu module works.

Is there a proper method for building elements that go into the $active_trail array, eg

$foo = array(
  'title' =&gt; $node-&gt;title,
  'href' =&gt; 'node/' . $node-&gt;nid,
  'link_path' =&gt; '',
  'localized_options' =&gt; array(),
  'type' =&gt; 0,
);


title and href are easy enough, but I don't quite get how the other play into this particular context.  It is easy enough to figure this out from what is there, but I would like to do "the right thing".

Is there a proper method (or best practice) for testing whether $item is a node and to load it?  Again, I can dpm($item), poke around, and get what I need.

I have what I need working, but it is messy and would like to fix it for the long term.
The properties for each trail item that are documented are the following:


title: Title of the item
href: Drupal path of the item
localized_options: Options for passing into the l() function
type: A menu type constant, such as MENU_DEFAULT_LOCAL_TASK, or 0 to indicate it's not really in the menu (used for the home page item)


The code that builds the breadcrumbs is the following.

foreach ($active_trail as $parent) {
  $breadcrumb[] = l($parent['title'], $parent['href'], $parent['localized_options']);
}


The other values (type and link_path) are not used to create the breadcrumbs, but they could be used from other modules that alter the breadcrumbs. Using the default values used from menu_set_active_trail() for those properties probably causes less compatibility problems with other modules.

$trail[] = array(
  'title' =&gt; t('Home'), 
  'href' =&gt; '&lt;front&gt;', 
  'link_path' =&gt; '', 
  'localized_options' =&gt; array(), 
  'type' =&gt; 0,
);



  Is there a proper method (or best practice) for testing whether $item is a node and to load it?


The $item argument hook_menu_breadcrumb_alter() gets is the value returned from menu_get_item(). If you want to check it is for a node, you can use the following code.

if (isset($item['load_functions'][2]) &amp;&amp; !empty($item['map'][3]) &amp;&amp; $item['load_functions'][4] == 'node_load') {
  $node = $router_item['map'][5];
}
else {
  // The menu item is not for a node.
}


That is the code executed from menu_get_object() when it is called with its default arguments.

References


menu_get_active_breadcrumb()
menu_set_active_trail()