You are here

simplemenu_inactive_parents.module in SimpleMenu 6

Same filename and directory in other branches
  1. 7 simplemenu_inactive_parents.module

Make all the simplemenu parent menu items non-clickable.

File

simplemenu_inactive_parents.module
View source
<?php

/**
 * @file
 * Make all the simplemenu parent menu items non-clickable.
 */

/**
 * \brief Alter the menu item link theme registry.
 *
 * This function grabs the simplemenu theme registry for the
 * menu_item_link theming. This gives us a way to remove the
 * link and replace it with a name (anchor) instead.
 *
 * This is only applied to the Simplemenu as intefering with
 * other menus could have unwanted side effects.
 *
 * \note
 * This is called at the time the theme registry is built.
 * It is then put in the cache until next time the registry
 * is built by the system (i.e. caches are cleared by user,
 * because a module is installed, etc.)
 */
function simplemenu_inactive_parents_theme_registry_alter(&$theme_registry) {
  global $theme;

  // Save theme function
  $themes = variable_get('simplemenu_inactive_parents_theme_function', array());
  $themes[$theme] = $theme_registry['menu_item_link']['function'];
  variable_set('simplemenu_inactive_parents_theme_function', $themes);

  // Replace with our own
  $theme_registry['menu_item_link']['function'] = 'simplemenu_inactive_parents_theme_menu_item_link';
}

/**
 * \brief Transform the menu item link.
 *
 * This function intercepts the menu item link theming function of
 * the system and 
 */
function simplemenu_inactive_parents_theme_menu_item_link($link) {
  global $theme;
  static $cnt = 0;

  // this is a drop down?
  if (!empty($link['has_children']) && simplemenu_running()) {
    ++$cnt;
    return '<a name="menu-id-' . $cnt . '">' . $link['title'] . '</a>';
  }

  // got a theme function?
  $themes = variable_get('simplemenu_inactive_parents_theme_function', array());
  if (isset($themes[$theme])) {
    return $themes[$theme]($link);
  }

  // somehow the preprocess function did not get called?!
  // use the core default
  return theme_menu_item_link($link);
}

// vim: ts=2 sw=2 et syntax=php

Functions

Namesort descending Description
simplemenu_inactive_parents_theme_menu_item_link \brief Transform the menu item link.
simplemenu_inactive_parents_theme_registry_alter \brief Alter the menu item link theme registry.