simplemenu_multi_menu.module 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. <?php
  2. // $Id$
  3. /**
  4. * @file
  5. * Make all the simplemenu parent menu items non-clickable.
  6. */
  7. /**
  8. * \brief Make the 'select' a list.
  9. *
  10. * Transform the menu selector from a drop-down to a list so people
  11. * can select more than one menu.
  12. */
  13. function simplemenu_multi_menu_form_simplemenu_admin_settings_alter(&$form, $form_state) {
  14. $form['default_menu']['simplemenu_menus'] = $form['default_menu']['simplemenu_menu'];
  15. unset($form['default_menu']['simplemenu_menu']);
  16. $def = variable_get('simplemenu_menus', array(variable_get('simplemenu_menu', 'navigation:0')));
  17. $form['default_menu']['simplemenu_menus']['#multiple'] = TRUE;
  18. $form['default_menu']['simplemenu_menus']['#title'] = t('Menus');
  19. $form['default_menu']['simplemenu_menus']['#default_value'] = $def;
  20. $form['default_menu']['simplemenu_menus']['#description'] = t('Select one or more menus to show each one of them (use Ctrl or Shift to select multiple entries.) Please, avoid selecting a parent and a child from the same menu.');
  21. }
  22. /**
  23. * \brief Replace the default with our own user selection.
  24. *
  25. * In this case we ignore the user selection unless the simplemenu_menus
  26. * was not yet defined, then we keep the default.
  27. */
  28. function simplemenu_multi_menu_simplemenu_menus_alter($all_menus) {
  29. $all_menus = variable_get('simplemenu_menus', $all_menus);
  30. }
  31. /**
  32. * \brief Alter the menu item link theme registry.
  33. *
  34. * This function grabs the simplemenu theme registry for the
  35. * menu_item_link theming. This gives us a way to remove the
  36. * link and replace it with a name (anchor) instead.
  37. *
  38. * This is only applied to the Simplemenu as intefering with
  39. * other menus could have unwanted side effects.
  40. *
  41. * \note
  42. * This is called at the time the theme registry is built.
  43. * It is then put in the cache until next time the registry
  44. * is built by the system (i.e. caches are cleared by user,
  45. * because a module is installed, etc.)
  46. */
  47. function simplemenu_multi_menu_theme_registry_alter(&$theme_registry) {
  48. global $theme;
  49. // Save theme function
  50. $themes = variable_get('simplemenu_multi_menu_theme_function', array());
  51. $themes[$theme] = $theme_registry['menu_item_link']['function'];
  52. variable_set('simplemenu_multi_menu_theme_function', $themes);
  53. // Replace with our own
  54. $theme_registry['menu_item_link']['function'] = 'simplemenu_multi_menu_theme_menu_item_link';
  55. }
  56. /**
  57. * \brief Transform the menu item link.
  58. *
  59. * This function intercepts the menu item link theming function of
  60. * the system and
  61. */
  62. function simplemenu_multi_menu_theme_menu_item_link($link) {
  63. global $theme;
  64. static $cnt = 0;
  65. // this is a drop down?
  66. if (!empty($link['simplemenu_multi_menu_root']) && variable_get('simplemenu_running', FALSE)) {
  67. ++$cnt;
  68. return '<a name="menu-id-' . $cnt . '">' . $link['title'] . '</a>';
  69. }
  70. // got a theme function?
  71. $themes = variable_get('simplemenu_multi_menu_theme_function', array());
  72. if (isset($themes[$theme])) {
  73. return $themes[$theme]($link);
  74. }
  75. // somehow the preprocess function did not get called?!
  76. // use the core default
  77. return theme_menu_item_link($link);
  78. }
  79. // vim: ts=2 sw=2 et syntax=php