You are here

menu_minipanels.install in Menu Minipanels 7

Same filename and directory in other branches
  1. 6 menu_minipanels.install
  2. 7.2 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() {

  // Check the requirements.
  $requirements = menu_minipanels_requirements('runtime');

  // See if an error was returned.
  if (!empty($requirements['menu_minipanels']['severity']) && $requirements['menu_minipanels']['severity'] == REQUIREMENT_ERROR) {

    // Return the message.
    drupal_set_message($requirements['menu_minipanels']['description'], 'warning');
  }

  // 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();
  }
}

/**
 * Implements hook_requirements().
 */
function menu_minipanels_requirements($phase) {
  $t = get_t();
  $requirements = array();
  if ($phase == 'runtime') {
    $qtip_path = FALSE;
    $filename = 'jquery.qtip-1.0.0-rc3.min.js';
    $module_path = drupal_get_path('module', 'menu_minipanels');

    // An array of possible paths, in descending order of preference.
    $possible_paths = array(
      // Ideally should be stored here.
      'sites/all/libraries/qtip',
      // Legacy paths, including some possible incorrect ones, but the
      // performance hit should be negligible.
      $module_path . '/js/lib/qtip',
      $module_path . '/js/lib',
      $module_path . '/js/qtip',
      $module_path . '/js',
      $module_path . '/qtip',
      $module_path,
    );

    // Proper Libraries API support.
    if (function_exists('libraries_get_path')) {
      $lib_path = libraries_get_path('qtip');
      if (!empty($lib_path) && !in_array($lib_path, $possible_paths)) {
        array_unshift($possible_paths, $lib_path);
      }
    }

    // Check each of the paths.
    foreach ($possible_paths as $path) {

      // If the file exists, this is the one we'll use.
      if (file_exists($path . '/' . $filename)) {
        $qtip_path = $path . '/' . $filename;
        continue;
      }
    }

    // If the file was not found, leave a message for the user.
    if (empty($qtip_path)) {
      $requirements['menu_minipanels'] = array(
        'description' => $t('The module is enabled but the qTip library has not been downloaded. This module will not work without qTip! Please see README.txt in the menu_minipanels directory for instructions on how to download qTip, or use <a href="http://drupal.org/project/drush">Drush</a> to download it via the following command:<br /><pre>drush download-qtip</pre>'),
        'severity' => REQUIREMENT_ERROR,
        'title' => $t('Menu MiniPanels'),
        'value' => $t('qTip library not found'),
      );
    }
    else {
      $requirements['menu_minipanels'] = array(
        'severity' => REQUIREMENT_OK,
        'title' => $t('Menu MiniPanels'),
        'value' => $t('qTip library in use: <em>!path</em>.', array(
          '!path' => $qtip_path,
        )),
      );
      $cid = 'menu_minipanels_qtip_path';
      cache_set($cid, $qtip_path);
    }
  }
  return $requirements;
}

/**
 * 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);
}

/**
 * Clear the theme cache so that the updated theme registry changes will take
 * effect.
 */
function menu_minipanels_update_7107() {
  drupal_theme_rebuild();
}

Functions

Namesort descending Description
menu_minipanels_install Implements hook_install().
menu_minipanels_requirements Implements hook_requirements().
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_update_7107 Clear the theme cache so that the updated theme registry changes will take effect.
_menu_minipanels_enable_menus Allow each menu to be menu_minipanel-ized, with some exceptions.