The basic set up: I have a custom content type called 'Guide'. Guides have an imagefield and some other custom fields; it is designed to be the top level/root of a book. All child pages of Guides are created with the regular book pages content type, but not all book pages on this site are children of Guides.
I have a little bit of custom code in a module for setting the breadcrumb of the Guide. There is an index page (View) that lists all Guides on the site, and when you're on a Guide node, the second breadcrumb is set to that page. Pretty basic stuff.
/**
* Implements hook_node_view
*/
function gta_web_guides_node_view($node, $view_mode, $langcode) {
$type_crumbs = array(
'web_guide' => array('title' => 'Web Guides', 'path' => 'web-guides'),
);
// Make sure we're rendering in full display mode AND the content type has a custom breadcrumb defined
if ('full' != $view_mode || !array_key_exists($node->type, $type_crumbs)) {
return;
}
$crumbs[] = l('Home', '<front>');
$crumbs[] = (!empty($type_crumbs[$node->type]['path'])) ? l($type_crumbs[$node->type]['title'], $type_crumbs[$node->type]['path']) : $type_crumbs[$node->type]['title'];
drupal_set_breadcrumb($crumbs);
}
Returns
Home -> Guides -> An Awesome Guide
Of course, when you click on a child page of the Guide, the breadcrumb does not include the Guides index page.
Home -> An Awesome Guide -> An Informative Child Page
So the question is, how do I get this:
Home -> Guides -> An Awesome Guide -> An Informative Child Page
How do I [1] Add the index page to the trail while [2] maintaining the full hierarchical breadcrumb for each book page and [3] only adding to breadcrumbs on book pages where the root is a Guide?
Comments
Solution
It works, but if anyone has ideas on how to improve this code, I am ready to learn.