You are here

function openlayers_requirements in Openlayers 7.2

Same name and namespace in other branches
  1. 7.3 openlayers.install \openlayers_requirements()

Implements hook_requirements().

1 call to openlayers_requirements()
openlayers_ui_init in modules/openlayers_ui/openlayers_ui.module
Implements hook_init().

File

./openlayers.install, line 246
This file holds the functions for the installing and enabling of the openlayers module.

Code

function openlayers_requirements($phase) {
  $req = array();
  $t = get_t();

  // We should not require a specfic version of the OpenLayers library, but
  // we should tell the administrator that specific versions are more
  // compatible than others.
  if ($phase == 'runtime') {
    $ol_library_version = 0;
    $current_library = variable_get('openlayers_source', OPENLAYERS_DEFAULT_LIBRARY);

    // As of 2.11, the hosted version supports the newest hosted
    // stable with an actual version number.  This used to be just under
    // the 'api' path.
    if (strpos($current_library, (string) OPENLAYERS_SUGGESTED_LIBRARY) !== FALSE) {
      $ol_library_version = OPENLAYERS_SUGGESTED_LIBRARY;
    }

    // Check if it is the default hosted.
    if ($current_library == 'http://openlayers.org/api/OpenLayers.js') {
      $ol_library_version = OPENLAYERS_HOSTED_API_LIBRARY;
    }

    // Finally, let's see if the client has sent us a value
    // from the UI module AJAX magic.
    $client = variable_get('openlayers_ui_version_check', '');
    if (strpos($client, (string) OPENLAYERS_SUGGESTED_LIBRARY) !== FALSE) {
      $ol_library_version = OPENLAYERS_SUGGESTED_LIBRARY;
    }

    // Check if suggest version.
    if ($ol_library_version == OPENLAYERS_SUGGESTED_LIBRARY) {
      $req['openlayers_old_presets'] = array(
        'title' => $t('OpenLayers library version'),
        'value' => $t('Using suggested compatible version %suggested.', array(
          '%suggested' => OPENLAYERS_SUGGESTED_LIBRARY,
        )),
        'severity' => REQUIREMENT_OK,
      );
    }
    else {
      $req['openlayers_old_presets'] = array(
        'title' => $t('OpenLayers library version'),
        'value' => $t('Not suggested compatible version.'),
        'description' => $t('Though you are very welcome to use whatever version of the OpenLayers library you want, it is suggested that you use version %suggested.  You are currently not using that version or we are unable to determine which version you are using.  Update your library settings at !settings.', array(
          '%suggested' => OPENLAYERS_SUGGESTED_LIBRARY,
          '!settings' => l(t('OpenLayers settings'), 'admin/structure/openlayers'),
        )),
        'severity' => REQUIREMENT_WARNING,
      );
    }
  }

  // There are some backwards compability for the shift from
  // preset to maps.  We want to communicate to administrators
  // that this will not be there forever.
  if ($phase == 'runtime') {

    // Check preset hook
    $presets = module_invoke_all('openlayers_presets');
    $found_presets = count($presets) > 0 ? TRUE : FALSE;

    // Check features
    $feature_names = array();
    $found_features = FALSE;
    if (module_exists('features')) {
      $features = features_get_features();
      foreach ($features as $feature) {

        // Only utilize enabled features and look for presets
        if ($feature->status > 0 && !empty($feature->info['features']['openlayers_map_presets'])) {
          $feature_names[] = $feature->name;
          $found_features = TRUE;
        }
      }
    }

    // Create requirement entries
    if ($found_presets) {
      $req['openlayers_old_presets'] = array(
        'title' => $t('OpenLayers Presets'),
        'value' => $t('Found old presets.'),
        'description' => $t('With the 7.x-2.x version of the OpenLayers module, map presets were renamed to just maps.  This has some implications on APIs and hooks.  One or more of of the modules installed on this site is utilizing the deprecated %hook.  Please <a href="@url">read the upgrade page</a>, then contact the module owner or fix the custom module yourself.', array(
          '%hook' => 'hook_openlayers_presets()',
          '@url' => url('http://drupal.org/node/1136810'),
        )),
        'severity' => REQUIREMENT_ERROR,
      );
    }
    if ($found_features) {
      $req['openlayers_old_features'] = array(
        'title' => $t('OpenLayers Presets'),
        'value' => $t('Found Features with presets.'),
        'description' => $t('With the 7.x-2.x version of the OpenLayers module, map presets were renamed to just maps.  This has some implications on APIs and hooks.  There are Features on this site that contain the old map presets.  Please <a href="@url">read the upgrade page</a>, and rebuild the following Features: %features', array(
          '@url' => url('http://drupal.org/node/1136810'),
          '%features' => implode(',', $feature_names),
        )),
        'severity' => REQUIREMENT_ERROR,
      );
    }
  }
  return $req;
}