You are here

function _acquia_lift_libraries_get_version in Acquia Lift Connector 7.2

Same name and namespace in other branches
  1. 7 acquia_lift.module \_acquia_lift_libraries_get_version()

Determines the version of a library.

This is used in case different variants of the library are shipped separately and, thus, different variants can contain different versions.

Parameters

array $library: An associative array containing all information about the library. The library is assumed to have the following non-standard keys:

  • variant order: An array of variant names, ordered from the most preferred variant to the least preferred.

array $options: An associative array with the following keys:

1 string reference to '_acquia_lift_libraries_get_version'
acquia_lift_libraries_info in ./acquia_lift.module
Implements hook_libraries_info().

File

./acquia_lift.module, line 2145
acquia_lift.module Provides Acquia Lift-specific personalization functionality.

Code

function _acquia_lift_libraries_get_version(&$library, $options = array()) {
  $versions = array();
  foreach ($library['variant order'] as $variant_name) {
    $variant = $library['version arguments']['variants'][$variant_name];

    // Use the libraries get version function to determine the version string.
    $versions[$variant_name] = libraries_get_version($library, $variant);
  }

  // If no versions could be found for any of the variant, there is no version
  // to return. If different versions have been found, there is no way to
  // determine the correct one. We cannot use the information on the preferred
  // variants because we cannot guarantee that a less preferred variant will not
  // be loaded. Null values are fine. Either that variant file doesn't exist
  // or id doesn't contain version information. As long as the there is no
  // conflicting version information, the check should pass.
  $versions = array_filter($versions, '_acquia_lift_libraries_filter_null_values');
  $version = array_unique($versions);
  $vcount = count($version);
  if ($vcount == 1) {

    // A version number exists, so suppress any errors that any individual
    // variant might have raised.
    unset($library['error']);
    unset($library['error message']);
    return array_shift($version);
  }
  elseif ($vcount > 1) {
    $output = array();
    foreach ($versions as $name => $v) {
      $output[] = t('@name (@v)', array(
        '@name' => $name,
        '@v' => $v,
      ));
    }
    $library['error'] = 'inconsistent versions';
    $library['error message'] = t('The library\'s variants returned inconsistent versions: @variant_info', array(
      '@variant_info' => implode(', ', $output),
    ));
  }

  // If the version count is zero, then let the error from libraries_get_version
  // propagate through.
}