You are here

accordion_menu.module in Accordion Menu 6

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

Provides primary Drupal hook implementations.

This module incorporates changes by:

  • solotandem: to port to Drupal 7
  • solotandem: to make output work in all browsers and behave well
  • solotandem: to handle flash of unstyled content in IE 7 and 8
  • solotandem and jerodfritz: to allow multiple accordion menu blocks (see #552450)

@author Jim Berry ("solotandem", http://drupal.org/user/240748) @author Suryanto Rachmat ("suryanto", http://drupal.org/user/104631)

File

accordion_menu.module
View source
<?php

/**
 * @file
 * Provides primary Drupal hook implementations.
 *
 * This module incorporates changes by:
 * - solotandem: to port to Drupal 7
 * - solotandem: to make output work in all browsers and behave well
 * - solotandem: to handle flash of unstyled content in IE 7 and 8
 * - solotandem and jerodfritz: to allow multiple accordion menu blocks
 *   (see #552450)
 *
 * @author Jim Berry ("solotandem", http://drupal.org/user/240748)
 * @author Suryanto Rachmat ("suryanto", http://drupal.org/user/104631)
 */

/**
 * Implements hook_perm().
 */
function accordion_menu_perm() {
  module_load_include('inc', 'accordion_menu', 'includes/info');
  return _accordion_menu_perm();
}

/**
 * Implements hook_menu().
 */
function accordion_menu_menu() {
  module_load_include('inc', 'accordion_menu', 'includes/info');
  return _accordion_menu_menu();
}

/**
 * Implements hook_theme().
 */
function accordion_menu_theme(&$existing, $type, $theme, $path) {
  module_load_include('inc', 'accordion_menu', 'includes/info');
  return _accordion_menu_theme($existing, $type, $theme, $path);
}

/**
 * Implements hook_block_info().
 */
function accordion_menu_block_info() {
  module_load_include('inc', 'accordion_menu', 'includes/info');
  return _accordion_menu_block_info();
}

/**
 * Implements hook_block_configure().
 */
function accordion_menu_block_configure($delta) {
  module_load_include('inc', 'accordion_menu', 'includes/configure');
  return _accordion_menu_block_configure($delta);
}

/**
 * Form validation handler for block_admin_configure().
 *
 * @see accordion_menu_block_configure()
 */
function accordion_menu_block_validate($form, &$form_state) {
  module_load_include('inc', 'accordion_menu', 'includes/configure');
  return _accordion_menu_block_validate($form, $form_state);
}

/**
 * Implements hook_block_save().
 */
function accordion_menu_block_save($delta, $edit) {
  module_load_include('inc', 'accordion_menu', 'includes/configure');
  _accordion_menu_block_save($delta, $edit);
}

/**
 * Implements hook_block_view().
 */
function accordion_menu_block_view($delta) {
  module_load_include('inc', 'accordion_menu', 'includes/view');
  return _accordion_menu_block_view($delta);
}

/**
 * Implements hook_block().
 */
function accordion_menu_block($op = 'list', $delta = 0, $edit = array()) {
  switch ($op) {
    case 'list':
      return accordion_menu_block_info();
      break;
    case 'configure':
      return accordion_menu_block_configure($delta);
      break;
    case 'save':
      accordion_menu_block_save($delta, $edit);
      break;
    case 'view':
      return accordion_menu_block_view($delta);
      break;
  }
}

/**
 * Implements hook_form_FORM_ID_alter().
 */
function accordion_menu_form_block_admin_configure_alter(&$form, &$form_state) {
  if ($form['module']['#value'] == 'accordion_menu') {
    $form['#validate'][] = 'accordion_menu_block_validate';
  }
}

/**
 * Returns the block configuration settings.
 *
 * @param string $delta
 *   The delta that uniquely identifies the block in the block system. If not
 *   specified, the default configuration will be returned.
 *
 * @return array
 *   An associative array of configuration settings.
 */
function accordion_menu_config($delta = NULL) {
  $config = array(
    // Our settings.
    'menu_name' => 'Menu ' . $delta,
    'menu_source' => 'navigation',
    'block_source' => '',
    'script_scope' => 'footer',
    'header_link' => FALSE,
    'menu_expanded' => FALSE,
    // jQuery UI accordion settings.
    'animated' => 'slide',
    'auto_height' => FALSE,
    'clear_style' => FALSE,
    'fill_space' => FALSE,
    'event' => 'mousedown',
    'header' => 'h3',
    'collapsible' => TRUE,
    // in jQuery UI 1.6 this is 'alwaysOpen'
    'navigation' => FALSE,
  );
  if ($delta) {

    // Get the block configuration settings.
    foreach ($config as $key => $value) {
      $config[$key] = variable_get("accordion_menu_{$delta}_{$key}", $config[$key]);
      if (in_array($key, array(
        'animated',
        'event',
        'script_scope',
      ))) {

        // Value may include letters only.
        // This is not validating the string, but simply requiring one.
        if (preg_match('@[^a-z]@', strtolower($config[$key]))) {
          $config[$key] = $value;
        }
      }
      elseif ($key == 'header') {

        // Value may include letters and a digit only.
        // This is not a true test for an HTML tag, but should prevent foul play.
        preg_match('@^([a-z]+([1-9]|)).*@', strtolower($config[$key]), $matches);
        if (empty($matches) || $matches[0] != $matches[1]) {
          $config[$key] = $value;
        }
      }
    }
  }
  $config['delta'] = $delta;
  return $config;
}

Functions

Namesort descending Description
accordion_menu_block Implements hook_block().
accordion_menu_block_configure Implements hook_block_configure().
accordion_menu_block_info Implements hook_block_info().
accordion_menu_block_save Implements hook_block_save().
accordion_menu_block_validate Form validation handler for block_admin_configure().
accordion_menu_block_view Implements hook_block_view().
accordion_menu_config Returns the block configuration settings.
accordion_menu_form_block_admin_configure_alter Implements hook_form_FORM_ID_alter().
accordion_menu_menu Implements hook_menu().
accordion_menu_perm Implements hook_perm().
accordion_menu_theme Implements hook_theme().