simplemenu_inactive_parents.module 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. <?php
  2. // $Id$
  3. /**
  4. * @file
  5. * Make all the simplemenu parent menu items non-clickable.
  6. */
  7. /**
  8. * \brief Alter the menu item link theme registry.
  9. *
  10. * This function grabs the simplemenu theme registry for the
  11. * menu_item_link theming. This gives us a way to remove the
  12. * link and replace it with a name (anchor) instead.
  13. *
  14. * This is only applied to the Simplemenu as intefering with
  15. * other menus could have unwanted side effects.
  16. *
  17. * \note
  18. * This is called at the time the theme registry is built.
  19. * It is then put in the cache until next time the registry
  20. * is built by the system (i.e. caches are cleared by user,
  21. * because a module is installed, etc.)
  22. */
  23. function simplemenu_inactive_parents_theme_registry_alter(&$theme_registry) {
  24. global $theme;
  25. // Save theme function
  26. $themes = variable_get('simplemenu_inactive_parents_theme_function', array());
  27. $themes[$theme] = $theme_registry['menu_item_link']['function'];
  28. variable_set('simplemenu_inactive_parents_theme_function', $themes);
  29. // Replace with our own
  30. $theme_registry['menu_item_link']['function'] = 'simplemenu_inactive_parents_theme_menu_item_link';
  31. }
  32. /**
  33. * \brief Transform the menu item link.
  34. *
  35. * This function intercepts the menu item link theming function of
  36. * the system and
  37. */
  38. function simplemenu_inactive_parents_theme_menu_item_link($link) {
  39. global $theme;
  40. static $cnt = 0;
  41. // this is a drop down?
  42. if (!empty($link['has_children']) && variable_get('simplemenu_running', FALSE)) {
  43. ++$cnt;
  44. return '<a name="menu-id-' . $cnt . '">' . $link['title'] . '</a>';
  45. }
  46. // got a theme function?
  47. $themes = variable_get('simplemenu_inactive_parents_theme_function', array());
  48. if (isset($themes[$theme])) {
  49. return $themes[$theme]($link);
  50. }
  51. // somehow the preprocess function did not get called?!
  52. // use the core default
  53. return theme_menu_item_link($link);
  54. }
  55. // vim: ts=2 sw=2 et syntax=php