You are here

menu_position.install in Menu Position 6

Same filename and directory in other branches
  1. 7.2 menu_position.install
  2. 7 menu_position.install

Provides install, update and un-install functions for menu_position.

File

menu_position.install
View source
<?php

/**
 * @file
 * Provides install, update and un-install functions for menu_position.
 */

/**
 * Implements hook_schema().
 */
function menu_position_schema() {
  $schema['menu_position_rules'] = array(
    'description' => 'Stores breadcrumb rules for nodes.',
    'fields' => array(
      'rid' => array(
        'description' => 'The primary identifier for a rule.',
        'type' => 'serial',
        'not null' => TRUE,
      ),
      'admin_title' => array(
        'description' => 'The administrative title of this rule.',
        'type' => 'varchar',
        'length' => 255,
        'default' => NULL,
      ),
      'enabled' => array(
        'description' => 'Whether the rule is enabled or not.',
        'type' => 'int',
        'size' => 'tiny',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 1,
      ),
      'conditions' => array(
        'description' => 'The serialized conditions for this rule.',
        'type' => 'text',
      ),
      'menu_name' => array(
        'description' => 'The menu of the menu link for this rule.',
        'type' => 'varchar',
        'length' => '32',
        'not null' => TRUE,
        'default' => '',
      ),
      'plid' => array(
        'description' => 'The parent menu link id for this rule.',
        'type' => 'int',
        'default' => NULL,
      ),
      'mlid' => array(
        'description' => 'The menu link id for this rule.',
        'type' => 'int',
        'default' => NULL,
      ),
      'weight' => array(
        'description' => 'The weight of this rule.',
        'type' => 'int',
        'size' => 'tiny',
        'not null' => FALSE,
        'default' => 0,
      ),
    ),
    'indexes' => array(
      'rule_enabled' => array(
        'enabled',
        'weight',
        'rid',
      ),
      'rule_weight' => array(
        'weight',
        'rid',
      ),
    ),
    'primary key' => array(
      'rid',
    ),
  );
  return $schema;
}

/**
 * Set the initial database schema ID.
 */
function menu_position_update_6100() {

  // No-op.
}

/**
 * Implements hook_enable().
 *
 * When the module is disabled, the menu links it owns are deleted. When
 * re-enabling this module, we need to ensure that any menu links are re-created
 * and to re-configure any old rules existing in the database.
 */
function menu_position_enable() {
  $enabled_rules = db_result(db_query('SELECT count(*) AS rule_count FROM {menu_position_rules} WHERE enabled = 1'));
  if ($enabled_rules) {
    drupal_set_message(t('Existing menu position rules were discovered. To ensure they continue to work, visit the <a href="!url">menu position rules admin page</a>.', array(
      '!url' => url('admin/build/menu-position'),
    )), 'error');

    // If we were to attempt menu_position_add_menu_link() here it would fail
    // because the module's router item isn't in the system yet. Instead we flag
    // the rule with a zero-value mlid and fix it in
    // menu_position_rules_form_callback().
    db_query('UPDATE {menu_position_rules} SET mlid = 0 WHERE enabled = 1');
  }
}

/**
 * Implements hook_install().
 */
function menu_position_install() {
  drupal_install_schema('menu_position');
}

/**
 * Implements hook_uninstall().
 */
function menu_position_uninstall() {
  drupal_uninstall_schema('menu_position');
}

Functions

Namesort descending Description
menu_position_enable Implements hook_enable().
menu_position_install Implements hook_install().
menu_position_schema Implements hook_schema().
menu_position_uninstall Implements hook_uninstall().
menu_position_update_6100 Set the initial database schema ID.