You are here

bigmenu.module in Big Menu 6

Same filename and directory in other branches
  1. 8 bigmenu.module
  2. 7 bigmenu.module
  3. 2.x bigmenu.module

alternative to core menu management

Needed when menus get to big to load on one page.

CONFLICTS WITH tiny_menu. Appropriately enough.

Some of the code here - especially the form cache rebuild trigger in bigmenu_slice_form_js() and the parameters sent on the AJAX URL string feel quite ungainly. However the main target - to be able to layer on this flexibility without modifying core - made a few work-arounds neccessary.

I did NOT use full Drupal core AHAH routines, as they seemed to rely on the entire form being submitted and rebuilt in the background each page load.

As the focus of this module is on *scaling* - I couldn't add that overhead, so the subforms are generated independently, not as part of the main overview form. This is why the bigmenu_slice_form_js() cheats form_cache a little bit.

@author Dan (dman) Morrison dan@coders.co.nz @version 2011

File

bigmenu.module
View source
<?php

/**
 * @file alternative to core menu management
 *
 * Needed when menus get to big to load on one page.
 *
 * CONFLICTS WITH tiny_menu. Appropriately enough.
 *
 * Some of the code here - especially the form cache rebuild trigger in
 * bigmenu_slice_form_js() and the parameters sent on the AJAX URL string feel
 * quite ungainly.
 * However the main target - to be able to layer on this flexibility without
 * modifying core - made a few work-arounds neccessary.
 *
 * I did NOT use full Drupal core AHAH routines, as they seemed to rely on the
 * entire form being submitted and rebuilt in the background each page load.
 *
 * As the focus of this module is on *scaling* - I couldn't add that overhead,
 * so the subforms are generated independently, not as part of the main overview
 * form. This is why the bigmenu_slice_form_js() cheats form_cache a little bit.
 *
 * @author Dan (dman) Morrison dan@coders.co.nz
 * @version 2011
 */

/**
 * Declare admin links and AJAX callbacks
 *
 * hook_menu()
 */
function bigmenu_menu() {
  $items['admin/build/bigmenu-customize/%menu'] = array(
    'title' => 'Customize menu',
    'page callback' => 'drupal_get_form',
    'page arguments' => array(
      'bigmenu_overview_form',
      3,
    ),
    'title callback' => 'menu_overview_title',
    'title arguments' => array(
      3,
    ),
    'access arguments' => array(
      'administer menu',
    ),
    'type' => MENU_CALLBACK,
    'file' => 'bigmenu.admin.inc',
  );

  // Edit just a part of a menu. Arg 5 is the parent menu link id
  $items['admin/build/bigmenu-customize/%menu/subform/%menu_link'] = array(
    'title' => 'Edit a slice of a menu',
    'page callback' => 'drupal_get_form',
    'page arguments' => array(
      'bigmenu_slice_form',
      3,
      5,
    ),
    'title callback' => 'bigmenu_parent_title',
    'title arguments' => array(
      5,
    ),
    'access arguments' => array(
      'administer menu',
    ),
    'type' => MENU_CALLBACK,
    'file' => 'bigmenu.admin.inc',
  );

  // Same as above, but triggers an equivalent json response
  // This also expects arg 7,8 to be a form ID and form cache id
  $items['admin/build/bigmenu-customize/%menu/subform/%menu_link/js'] = array(
    'page callback' => 'bigmenu_slice_form_js',
    'page arguments' => array(
      3,
      5,
    ),
    'access arguments' => array(
      'administer menu',
    ),
    'type' => MENU_CALLBACK,
    'file' => 'bigmenu.admin.inc',
  );
  $items['admin/build/bigmenu/alias_autocomplete'] = array(
    'type' => MENU_CALLBACK,
    'access arguments' => array(
      'administer menu',
    ),
    'page callback' => 'bigmenu_alias_autocomplete',
    'file' => 'bigmenu.admin.inc',
  );
  return $items;
}

/**
 * Take over core menu admin page
 *
 * hook_menu_alter()
 *
 * TODO - should be an admin toggle for this setting
 */
function bigmenu_menu_alter(&$items) {
  $items['admin/build/menu-customize/%menu']['page arguments'] = array(
    'bigmenu_overview_form',
    3,
  );
  $items['admin/build/menu-customize/%menu']['file'] = 'bigmenu.admin.inc';
  $items['admin/build/menu-customize/%menu']['file path'] = drupal_get_path('module', 'bigmenu');

  #dpm($items['admin/build/menu-customize/%menu']);
}

/**
 * Add our own option into the menu management box of the node edit form
 *
 * hook_form_alter()
 *
 * ISSUE:
 * I don't know how to stop the normal node edit form menu form_alter()
 * from running each time (and loading all the options each time)
 * even though I'm planning to override it.
 * There could be a performance issue there.
 */
function bigmenu_form_alter(&$form, $form_state, $form_id) {

  // Only add this util if the switch is on. Currently no UI, currently unfinished
  if (!variable_get('bigmenu_alter_node_form', FALSE)) {
    return;
  }
  if (isset($form['#node']) && $form['#node']->type . '_node_form' == $form_id) {
    $item = $form['#node']->menu;
    if ($item['mlid']) {

      // There is an existing link.
    }
    $form['menu']['bigmenu_url'] = array(
      '#type' => 'textfield',
      '#title' => t('Menu parent path'),
      '#description' => t('Enter just the URL or path of your desired menu parent.'),
      '#autocomplete_path' => 'admin/build/bigmenu/alias_autocomplete',
    );
  }
}

/**
 * Implemenation of hook_theme().
 */
function bigmenu_theme() {
  return array(
    'bigmenu_overview_form' => array(
      'file' => 'bigmenu.admin.inc',
      'arguments' => array(
        'form' => NULL,
      ),
    ),
  );
}

/**
 * Implementation of hook_enable()
 *
 * Ensure we load after the usual core
 */
function bigmenu_enable() {
  db_query('UPDATE {system} SET weight = 10 WHERE name = "bigmenu"');
}

Functions

Namesort descending Description
bigmenu_enable Implementation of hook_enable()
bigmenu_form_alter Add our own option into the menu management box of the node edit form
bigmenu_menu Declare admin links and AJAX callbacks
bigmenu_menu_alter Take over core menu admin page
bigmenu_theme Implemenation of hook_theme().