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. * Override of execute().
  8. */
  9. function execute(&$vars = NULL) {
  10. if ($active_paths = $this->get_active_paths()) {
  11. $breadcrumb = array(l(t('Home'), '<front>', array('purl' => array('disabled' => TRUE))));
  12. foreach ($active_paths as $path) {
  13. $result = db_select('menu_links')
  14. ->fields('menu_links', array('p1', 'p2', 'p3', 'p4', 'p5', 'p6', 'p7', 'p8'))
  15. ->condition('hidden', 0)
  16. ->condition('link_path', $path)
  17. ->execute();
  18. while ($parents = $result->fetchAssoc()) {
  19. $set = FALSE;
  20. foreach (array_filter($parents) as $plid) {
  21. $parent = menu_link_load($plid);
  22. if ($parent && $parent['access'] && empty($parent['hidden']) && !empty($parent['title'])) {
  23. $set = TRUE;
  24. $breadcrumb[] = l($parent['title'], $parent['href']);
  25. }
  26. }
  27. // Only set the breadcrumb if one or more links were added to the
  28. // trail. If not, continue iterating through possible menu links.
  29. if ($set) {
  30. drupal_set_breadcrumb($breadcrumb);
  31. break;
  32. }
  33. }
  34. }
  35. }
  36. }
  37. }