Skip to content

Instantly share code, notes, and snippets.

@ccamara
Last active December 17, 2015 02:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ccamara/5538831 to your computer and use it in GitHub Desktop.
Save ccamara/5538831 to your computer and use it in GitHub Desktop.
Drupal: Custom breadcrumbs for books showing hierarchy and parent's taxonomy #drupal #breadcrumbs
<?php /**
* Custom breadcrumbs for books showing hierarchy and parent's taxonomy.
*/
function feature_book_node_view($node, $view_mode, $langcode) {
if ($node->type == 'books') {
// Node is a parent.
if ($node->book['p2'] == '0') {
$wrapper = entity_metadata_wrapper('node', $node);
$themawrapper = $wrapper->field_taxonomy[0]; // Replace field_taxonomy with the propper taxonomy field.
$breadcrumb = array();
// Home.
$breadcrumb[] = l(t('Home'), '<front>');
// Thema for this node
$breadcrumb[] = l($themawrapper->name->value(), $themawrapper->url->value());
// Title for this node.
//$breadcrumb[] = $wrapper->title->value();
drupal_set_breadcrumb($breadcrumb);
}
else {
// Node is a child.
$wrapper = entity_metadata_wrapper('node', $node);
// We obtain this node's parent.
$parentwrapper = $wrapper->book;
$themawrapper = $parentwrapper->field_thema[0]; // Replace field_taxonomy with the propper taxonomy field.
$breadcrumb = array();
// Home
$breadcrumb[] = l(t('Home'), '<front>');
// Taxonomy for this node's parent
$breadcrumb[] = l($themawrapper->name->value(), $themawrapper->url->value());
// Parent's title
$breadcrumb[] = l($parentwrapper->title->value(), $parentwrapper->url->value());
// Title for this node
//$breadcrumb[] = $wrapper->title->value();
drupal_set_breadcrumb($breadcrumb);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment