You are here

dhtml_menu.module in DHTML Menu 6

dhtml_menu.modle Allow click expansion of the menu tree via javascript, with graceful degradation.

File

dhtml_menu.module
View source
<?php

/**
 * @file dhtml_menu.modle
 * Allow click expansion of the menu tree via javascript, with
 * graceful degradation.
 */

/**
 * Implementation of hook_form_alter().
 *
 * @ingroup form
 */
function dhtml_menu_form_block_admin_configure_alter(&$form, $form_state) {
  if ($form['module']['#value'] == 'menu' or $form['module']['#value'] == 'user') {
    $dhtml_menus = variable_get('dhtml_menus_menus', array());
    $form['dhtml_menu'] = array(
      '#default_value' => $dhtml_menus[$form['delta']['#value']],
      '#title' => t('Use the DHTML effect'),
      '#type' => 'checkbox',
      '#weight' => -3,
    );
    $form['#validate']['_dhtml_menu_form_block_validate'] = '_dhtml_menu_form_block_validate';
  }
}

/**
 * Save the DHTML options
 *
 * @ingroup form
 */
function _dhtml_menu_form_block_validate(&$form, $form_state) {
  $delta = $form_state['values']['delta'];
  if ($delta == 1 and $form_state['values']['module'] == 'user') {
    $delta = 'navigation';
  }
  $dhtml_menus = variable_get('dhtml_menus_menus', array());
  $dhtml_menus[$delta] = $form_state['values']['dhtml_menu'];
  variable_set('dhtml_menus_menus', $dhtml_menus);
}

/**
 * Implementation of hook_menu().
 */
function dhtml_menu_menu() {
  $items['admin/settings/dhtml_menu'] = array(
    'access arguments' => array(
      'access administration pages',
    ),
    'description' => 'Adds new menus with DHTML to reduce page refreshes',
    'file' => 'dhtml_menu.admin.inc',
    'title' => 'DHTML Menu',
    'page callback' => 'drupal_get_form',
    'page arguments' => array(
      '_dhtml_menu_settings',
    ),
  );
  return $items;
}

/**
 * Implementation of hook_preprocess().
 * Change the normal behaviour ('theming') of hook_block().
 *
 * @ingroup themable
 */
function dhtml_menu_preprocess_block(&$variables) {
  $delta = $variables['block']->delta;
  if ($delta == 1 and $variables['block']->module == 'user') {
    $delta = 'navigation';
  }

  // Get the dhtml_menus_menus variable
  $dhtml_menus = variable_get('dhtml_menus_menus', array());

  // If the menu has the DHTML menu option enabled,
  // replace the entire block content to its DHTML equivalent
  if (!empty($dhtml_menus[$delta])) {
    include_once drupal_get_path('module', 'dhtml_menu') . '/dhtml_menu.inc';
    $variables['block']->content = _dhtml_menu_build_menu($delta);
  }
}

/**
 * Implementation of hook_theme().
 */
function dhtml_menu_theme($existing, $type) {
  $theme['dhtml_menu_item'] = array(
    'arguments' => array(
      'item' => array(),
      'id' => NULL,
    ),
    'file' => 'dhtml_menu.inc',
  );
  $theme['dhtml_menu_tree'] = array(
    'arguments' => array(
      'tree' => array(),
      'parent' => NULL,
      'pid' => NULL,
    ),
    'file' => 'dhtml_menu.inc',
  );
  return $theme;
}

Functions

Namesort descending Description
dhtml_menu_form_block_admin_configure_alter Implementation of hook_form_alter().
dhtml_menu_menu Implementation of hook_menu().
dhtml_menu_preprocess_block Implementation of hook_preprocess(). Change the normal behaviour ('theming') of hook_block().
dhtml_menu_theme Implementation of hook_theme().
_dhtml_menu_form_block_validate Save the DHTML options