You are here

menu_minipanels.install in Menu Minipanels 7.2

Same filename and directory in other branches
  1. 6 menu_minipanels.install
  2. 7 menu_minipanels.install

Installation and update scripts for Menu_MiniPanels.

File

menu_minipanels.install
View source
<?php

/**
 * @file
 * Installation and update scripts for Menu_MiniPanels.
 */

/**
 * Implements hook_install().
 */
function menu_minipanels_install() {

  // Allow each menu to be menu_minipanel-ized, with some exceptions.
  _menu_minipanels_enable_menus();
}

/**
 * Implements hook_uninstall().
 */
function menu_minipanels_uninstall() {

  // Delete variables.
  variable_del('menu_minipanels_hover');
  variable_del('menu_minipanels_default_callbacks');
  variable_del('menu_minipanels_exclude_paths');
  foreach (menu_get_names() as $menu) {
    variable_del('menu_minipanels_' . $menu . '_enabled');
  }

  // Remove menu item settings.
  $results = db_query("SELECT menu_name, mlid, options FROM {menu_links} WHERE options LIKE ('%menu_minipanels%')");
  foreach ($results as $menu) {

    // The menu item's options are serialized.
    $options = unserialize($menu->options);
    unset($options['minipanel']);
    unset($options['menu_minipanels_hover']);

    // Update the menu item record.
    db_update('menu_links')
      ->fields(array(
      'options' => serialize($options),
    ))
      ->condition('menu_name', $menu->menu_name)
      ->condition('mlid', $menu->mlid)
      ->execute();
  }
}

/**
 * Allow each menu to be menu_minipanel-ized, with some exceptions.
 */
function _menu_minipanels_enable_menus() {

  // Ignore the Navigation, Admin Menu and Devel menus, those have to be
  // manually enabled.
  $ignore_menus = array(
    'navigation',
    'admin_menu',
    'devel',
  );
  foreach ($ignore_menus as $menu) {
    variable_set('menu_minipanels_' . $menu . '_enabled', FALSE);
  }

  // Enable all of the custom menus that isn't already disabled. Only work with
  // the custom menus, don't look at the shortcut sets.
  $result = db_query("SELECT menu_name FROM {menu_custom} ORDER BY title", array(), array(
    'fetch' => PDO::FETCH_ASSOC,
  ));
  foreach ($result as $menu) {
    if (!in_array($menu['menu_name'], $ignore_menus)) {
      variable_set('menu_minipanels_' . $menu['menu_name'] . '_enabled', TRUE);
    }
  }
}

/**
 * Implementations of hook_update_N().
 */

/**
 * Warn the user to re-save their menu configurations.
 */
function menu_minipanels_update_7100() {
  drupal_set_message(t('Recent changes to the Menu MiniPanels module require that any menus with attached MiniPanels have their configuration re-saved.'));
}

/**
 * // Placeholder.
 */
function menu_minipanels_update_7101() {

  // Do nothing.
}

/**
 * Change the menu configurations to the new structure.
 */
function menu_minipanels_update_7102() {

  // Allow each menu to be menu_minipanel-ized, with some exceptions.
  _menu_minipanels_enable_menus();
  drupal_set_message(t("The menus have been converted to use the new Menu MiniPanels settings, though you should still check each menu to ensure that it is correctly enabled via each menu's edit page. You may also want to disable ones which are not necessary for a small performance improvement."));
}

/**
 * Inform the user about the settings page moving.
 */
function menu_minipanels_update_7103() {
  menu_cache_clear_all();
  drupal_set_message(t('Please note that the <a href=":url">Menu_MiniPanels configuration page</a> has been relocated.', array(
    ':url' => 'admin/config/user-interface/menu_minipanels',
  )));
}

/**
 * Change from the show_admin to the exclude_pages variable.
 */
function menu_minipanels_update_7104() {

  // Convert the existing show_admin variable.
  if (variable_get('menu_minipanels_show_admin', TRUE)) {
    variable_set('menu_minipanels_exclude_paths', "admin\nadmin/*");
  }
  else {
    variable_set('menu_minipanels_exclude_paths', '');
  }

  // Delete the existing show_admin variable.
  variable_del('menu_minipanels_show_admin');
}

/**
 * Ensure that the menus are correctly enabled.
 */
function menu_minipanels_update_7105() {

  // This may have been inserted by accident.
  variable_del('menu_minipanels_Array_enabled');
  _menu_minipanels_enable_menus();
}

/**
 * Disable the menu for the Admin Menu and Devel modules.
 */
function menu_minipanels_update_7106() {
  variable_set('menu_minipanels_admin_menu_enabled', FALSE);
  variable_set('menu_minipanels_devel_enabled', FALSE);
}

Functions

Namesort descending Description
menu_minipanels_install Implements hook_install().
menu_minipanels_uninstall Implements hook_uninstall().
menu_minipanels_update_7100 Warn the user to re-save their menu configurations.
menu_minipanels_update_7101 // Placeholder.
menu_minipanels_update_7102 Change the menu configurations to the new structure.
menu_minipanels_update_7103 Inform the user about the settings page moving.
menu_minipanels_update_7104 Change from the show_admin to the exclude_pages variable.
menu_minipanels_update_7105 Ensure that the menus are correctly enabled.
menu_minipanels_update_7106 Disable the menu for the Admin Menu and Devel modules.
_menu_minipanels_enable_menus Allow each menu to be menu_minipanel-ized, with some exceptions.