context_condition_menu.inc

  1. cis7 sites/all/modules/ulmus/context/plugins/context_condition_menu.inc
  2. cle7 sites/all/modules/ulmus/context/plugins/context_condition_menu.inc
  3. ecd7 sites/all/modules/ulmus/context/plugins/context_condition_menu.inc
  4. elmsmedia7 sites/all/modules/ulmus/context/plugins/context_condition_menu.inc
  5. harmony7 sites/all/modules/ulmus/context/plugins/context_condition_menu.inc
  6. icor7 sites/all/modules/ulmus/context/plugins/context_condition_menu.inc
  7. meedjum_blog7 sites/all/modules/ulmus/context/plugins/context_condition_menu.inc
  8. mooc7 sites/all/modules/ulmus/context/plugins/context_condition_menu.inc

Classes

Namesort descending Description
context_condition_menu Expose menu items as a context condition.

File

sites/all/modules/ulmus/context/plugins/context_condition_menu.inc
View source
  1. <?php
  2. /**
  3. * Expose menu items as a context condition.
  4. */
  5. class context_condition_menu extends context_condition {
  6. /**
  7. * Override of condition_values().
  8. */
  9. function condition_values() {
  10. if (module_exists('menu')) {
  11. $menus = menu_parent_options(menu_get_menus(), array('mlid' => 0));
  12. $root_menus = array();
  13. foreach ($menus as $key => $name) {
  14. $id = explode(':', $key);
  15. if ($id[1] == '0') {
  16. $root_menus[$id[0]] = check_plain($name);
  17. }
  18. else {
  19. $link = menu_link_load($id[1]);
  20. $identifier = $link['link_path'];
  21. $root_menu = $root_menus[$id[0]];
  22. while (isset($menus[$root_menu][$identifier])) {
  23. $identifier .= "'";
  24. }
  25. $menus[$root_menu][$identifier] = $name;
  26. }
  27. unset($menus[$key]);
  28. }
  29. array_unshift($menus, "-- " . t('None') . " --");
  30. }
  31. else {
  32. $menus = array();
  33. }
  34. return $menus;
  35. }
  36. /**
  37. * Override of condition_form().
  38. * Use multiselect widget.
  39. */
  40. function condition_form($context) {
  41. $form = parent::condition_form($context);
  42. $menu_count = count($form['#options'], COUNT_RECURSIVE);
  43. $form['#type'] = 'select';
  44. $form['#multiple'] = TRUE;
  45. $form['#attributes'] = array('size' => $menu_count > 20 ? 20 : $menu_count);
  46. return $form;
  47. }
  48. /**
  49. * Override of condition_form_submit().
  50. * Trim any identifier padding for non-unique path menu items.
  51. */
  52. function condition_form_submit($values) {
  53. // Trim any identifier padding for non-unique path menu items.
  54. $values = parent::condition_form_submit($values);
  55. $trimmed = array();
  56. foreach ($values as $key => $value) {
  57. $trimmed[trim($key, "'")] = trim($value, "'");
  58. }
  59. return $trimmed;
  60. }
  61. /**
  62. * Override of execute().
  63. */
  64. function execute() {
  65. if ($this->condition_used()) {
  66. $trail = menu_get_active_trail();
  67. foreach ($trail as $item) {
  68. if (!empty($item['href'])) {
  69. foreach ($this->get_contexts($item['href']) as $context) {
  70. $this->condition_met($context, $item['href']);
  71. }
  72. }
  73. }
  74. }
  75. }
  76. }