context_reaction_breadcrumb.inc 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. <?php
  2. /**
  3. * Set the breadcrumb using a context reaction.
  4. */
  5. class context_reaction_breadcrumb extends context_reaction_menu {
  6. /**
  7. * Overrides set_active_trail_from_link to set the breadcrumb instead of the menu path.
  8. */
  9. function set_active_trail_from_link($item) {
  10. $breadcrumb = array(l(t('Home'), '<front>'));
  11. $result = db_select('menu_links')
  12. ->fields('menu_links', array('p1', 'p2', 'p3', 'p4', 'p5', 'p6', 'p7', 'p8'))
  13. ->condition('hidden', 0)
  14. ->condition('link_path', $item['link_path'])
  15. ->execute();
  16. while ($parents = $result->fetchAssoc()) {
  17. $set = FALSE;
  18. foreach (array_filter($parents) as $plid) {
  19. $parent = menu_link_load($plid);
  20. if ($parent && $parent['access'] && empty($parent['hidden']) && !empty($parent['title'])) {
  21. $set = TRUE;
  22. $breadcrumb[] = l($parent['title'], $parent['href']);
  23. }
  24. }
  25. // Only set the breadcrumb if one or more links were added to the
  26. // trail. If not, continue iterating through possible menu links.
  27. if ($set) {
  28. drupal_set_breadcrumb($breadcrumb);
  29. break;
  30. }
  31. }
  32. }
  33. /**
  34. * Return the title to be used for the current menu item.
  35. */
  36. function get_link_title($item) {
  37. return module_exists('i18n_menu') ? _i18n_menu_link_title($item) : $item['title'];
  38. }
  39. }