You are here

accordion_menu.module in Accordion Menu 7

Same filename and directory in other branches
  1. 6 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_permission().
 */
function accordion_menu_permission() {
  module_load_include('inc', 'accordion_menu', 'includes/info');
  return _accordion_menu_permission();
}

/**
 * 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_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 1.6 through 1.8 accordion settings.
        'animated' => 'slide',
        'auto_height' => FALSE,
        'clear_style' => FALSE,
        'fill_space' => FALSE,
        'event' => 'mousedown',
        'header' => 'h3',
        'collapsible' => TRUE,
        'navigation' => FALSE,
        'icons' => TRUE,
        'header_icon' => 'ui-icon-triangle-1-e',
        'selected_icon' => 'ui-icon-triangle-1-s',
        'empty_icon' => 'ui-icon-triangle-1-s',
    */

    // jQuery UI 1.10 accordion settings.
    // Although 'animate' supports a duration this seems not useful in a menu.
    'animate' => 'swing',
    'collapsible' => TRUE,
    'event' => 'mousedown',
    'header' => 'h3',
    'height_style' => 'content',
    'icons' => TRUE,
    'header_icon' => 'ui-icon-triangle-1-e',
    'active_icon' => 'ui-icon-triangle-1-s',
    'empty_icon' => 'ui-icon-blank',
  );
  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(
        'animate',
        '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;
}