You are here

function _quickedit_libraries_get_version in Quick Edit 7

Determines the version of an Quick Edit 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 '_quickedit_libraries_get_version'
quickedit_libraries_info in ./quickedit.module
Implements hook_libraries_info().

File

includes/libraries.inc, line 25
Logic to nicely integrate with Libraries API.

Code

function _quickedit_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, '_quickedit_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.
}