Skip to content

Instantly share code, notes, and snippets.

@SebCorbin
Last active November 9, 2015 12:53
Show Gist options
  • Save SebCorbin/37c795b016de72dadfd5 to your computer and use it in GitHub Desktop.
Save SebCorbin/37c795b016de72dadfd5 to your computer and use it in GitHub Desktop.
<?php
/**
* Implements hook_page_delivery_callback_alter().
*/
function fixtrail_page_delivery_callback_alter(&$callback) {
$current_path = current_path();
// Only work on normal pages, not ajax nor admin pages.
if ($callback != 'drupal_deliver_html_page' || path_is_admin($current_path)) {
return;
}
$parent_path = NULL;
// Set the nearest parent given certain conditions.
$item = menu_get_item();
if ($item['path'] == 'node/%') {
$node = $item['map'][1];
if ($node->type == 'evenement') {
$parent_path = 'evenements';
}
elseif ($node->type == 'dossier') {
$parent_path = 'dossiers';
}
elseif ($node->type == 'produit') {
$parent_path = 'produits';
}
}
elseif ($item['path'] == 'taxonomy/term/%') {
$term = $item['map'][2];
if ($term->vocabulary_machine_name == 'lexique') {
$parent_path = 'lexique';
}
}
// If parent found, set it for menu tree trail future build.
if ($parent_path) {
menu_tree_set_path('menu-header-main', $parent_path);
menu_link_get_preferred($parent_path);
// Fool drupal so that it take the correct link to build the breadcrumb.
$preferred_links = &drupal_static('menu_link_get_preferred');
$preferred_links[$current_path] = $preferred_links[$parent_path];
}
}
/**
* Implements hook_menu_breadcrumb_alter().
*/
function fixtrail_menu_breadcrumb_alter(&$active_trail, $item) {
// Add the current page to the breadcrumb, if not already done.
$end = end($active_trail);
if (current_path() != $end['href']) {
$active_trail[] = $item;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment