editmenu_multi_menu.module 3.0 KB

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