context_reaction_breadcrumb.inc 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839
  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. $result = db_select('menu_links')
  11. ->fields('menu_links', array('p1', 'p2', 'p3', 'p4', 'p5', 'p6', 'p7', 'p8'))
  12. ->condition('hidden', 0)
  13. ->condition('link_path', $item['link_path'])
  14. ->execute();
  15. while ($parents = $result->fetchAssoc()) {
  16. $set = FALSE;
  17. foreach (array_filter($parents) as $plid) {
  18. $parent = menu_link_load($plid);
  19. if ($parent && $parent['access'] && empty($parent['hidden']) && !empty($parent['title'])) {
  20. $set = TRUE;
  21. $breadcrumb[] = l($parent['title'], $parent['href']);
  22. }
  23. }
  24. // Only set the breadcrumb if one or more links were added to the
  25. // trail. If not, continue iterating through possible menu links.
  26. if ($set) {
  27. drupal_set_breadcrumb($breadcrumb);
  28. break;
  29. }
  30. }
  31. }
  32. /**
  33. * Return the title to be used for the current menu item.
  34. */
  35. function get_link_title($item) {
  36. return module_exists('i18n_menu') ? _i18n_menu_link_title($item) : $item['title'];
  37. }
  38. }