editmenu_inactive_parents.module 1.8 KB

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