You are here

function hierarchical_select_requirements in Hierarchical Select 5.3

Same name and namespace in other branches
  1. 6.3 hierarchical_select.module \hierarchical_select_requirements()
  2. 7.3 hierarchical_select.module \hierarchical_select_requirements()

Implementation of hook_requirements().

File

./hierarchical_select.module, line 144
This module defines the "hierarchical_select" form element, which is a greatly enhanced way for letting the user select items in a hierarchy.

Code

function hierarchical_select_requirements($phase) {
  $requirements = array();
  if ($phase == 'runtime') {

    // Check if all hook_update_n() hooks have been executed.
    require_once 'includes/install.inc';
    drupal_load_updates();
    $updates = drupal_get_schema_versions('hierarchical_select');
    $current = drupal_get_installed_schema_version('hierarchical_select');
    $up_to_date = end($updates) == $current;
    $jquery_update_v2 = file_exists(drupal_get_path('module', 'jquery_update') . '/compat.js');
    $jquery_interface = module_exists('jquery_interface');
    $hierarchical_select_weight = db_result(db_query("SELECT weight FROM {system} WHERE type = 'module' AND name = 'hierarchical_select'"));
    $core_overriding_modules = array(
      'hs_book',
      'hs_menu',
      'hs_taxonomy',
    );
    $path_errors = array();
    foreach ($core_overriding_modules as $module) {
      $filename = db_result(db_query("SELECT filename FROM {system} WHERE type = 'module' AND name = '%s'", $module));
      if (strpos($filename, 'modules/') === 0) {
        $module_info = _module_parse_info_file(dirname($filename) . "/{$module}.info");
        $path_errors[] = t('!module', array(
          '!module' => $module_info['name'],
        ));
      }
    }
    $weight_errors = array();
    foreach (module_implements('hierarchical_select_root_level') as $module) {
      $weight = db_result(db_query("SELECT weight FROM {system} WHERE name = '%s'", $module));
      if (!($hierarchical_select_weight > $weight)) {
        $filename = db_result(db_query("SELECT filename FROM {system} WHERE type = 'module' AND name = '%s'", $module));
        $module_info = _module_parse_info_file(dirname($filename) . "/{$module}.info");
        $weight_errors[] = t('!module (!weight)', array(
          '!module' => $module_info['name'],
          '!weight' => $weight,
        ));
      }
    }
    if ($up_to_date && $jquery_update_v2 && !$jquery_interface && !count($path_errors) && !count($weight_errors)) {
      $value = t('All updates installed. jQuery Update 2.x installed. Implementation modules are installed correctly.');
      $description = '';
      $severity = REQUIREMENT_OK;
    }
    elseif (!$up_to_date) {
      $value = t('Not all updates installed!');
      $description = t('Please run update.php to install the latest updates!
        You have installed update !installed_update, but the latest update is
        !latest_update!', array(
        '!installed_update' => $current,
        '!latest_update' => end($updates),
      ));
      $severity = REQUIREMENT_ERROR;
    }
    elseif (!$jquery_update_v2) {
      $value = t('jQuery Update 1.x installed!');
      $description = t('Please upgrade to jQuery Update 2.x! jQuery Update
        1.x contains jQuery 1.1.x, which is incompatible with the Javascript
        code of Hierarchical Select!');
      $severity = REQUIREMENT_ERROR;
    }
    elseif ($jquery_interface) {
      $value = t('jQuery Interface installed!');
      $description = t('Please disable and uninstall jQuery Interface, as it
        is incompatible with jQuery Update 2. It is very buggy anyway and any
        module that uses it should upgrade to jQuery UI.');
      $severity = REQUIREMENT_ERROR;
    }
    elseif ($path_errors) {
      $value = t('Modules incorrectly installed!');
      $description = t("The following modules implement Hierarchical Select module for Drupal\n        core modules, but are installed in the wrong location. They're\n        installed in core's <code>modules</code> directory, but should be\n        installed in either the <code>sites/all/modules</code> directory or a\n        <code>sites/yoursite.com/modules</code> directory") . ':' . theme('item_list', $path_errors);
      $severity = REQUIREMENT_ERROR;
    }
    elseif ($weight_errors) {
      $value = t('Module weight incorrectly configured!');
      $description = t('The weight of the Hierarchical Select module (!weight) is not
        strictly higher than the weight of the following modules', array(
        '!weight' => $hierarchical_select_weight,
      )) . ':' . theme('item_list', $weight_errors);
      $severity = REQUIREMENT_ERROR;
    }
    $requirements['hierarchical_select'] = array(
      'title' => t('Hierarchical Select'),
      'value' => $value,
      'description' => $description,
      'severity' => $severity,
    );
  }
  return $requirements;
}