The docs for hook_libraries_info() state that both 'version' and 'version callback' are optional.

This is technically true, but if neither is defined, the library will never be detected as installed, as this code in libraries_detect() shows:

  if (!isset($library['version'])) {
    // We support both a single parameter, which is an associative array, and an
    // indexed array of multiple parameters.
    if (isset($library['version arguments'][0])) {
      // Add the library as the first argument.
      $library['version'] = call_user_func_array($library['version callback'], array_merge(array($library), $library['version arguments']));
    }
    else {
      $library['version'] = $library['version callback']($library, $library['version arguments']);
    }
    if (empty($library['version'])) {
      $library['error'] = 'not detected';
      $library['error message'] = t('The version of the %library library could not be detected.', array(
        '%library' => $library['name'],
      ));
      return $library;
    }
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

tstoeckler’s picture

Status: Active » Needs review
FileSize
2.49 KB

Hmmm, it's even a bit more complicated than that, because 'version callback' defaults to 'libraries_get_version'. Does the attached patch clarify the situation?

tstoeckler’s picture

Wait, I messed that up. How's this one?

Status: Needs review » Needs work

The last submitted patch, libraries-version-docs-improvement-2.patch, failed testing.

tstoeckler’s picture

Status: Needs work » Needs review
FileSize
2.98 KB

Let's try this again.

tstoeckler’s picture

tstoeckler’s picture

Status: Needs review » Fixed

Status: Fixed » Closed (fixed)
Issue tags: +

Automatically closed - issue fixed for 2 weeks with no activity.

joachim’s picture

Issue summary: View changes
Status: Closed (fixed) » Active

The patch does not seem to have changed the docs about the 'version' property.

A developer reading down the list of properties to see which are required would still think both of these are optional.

tstoeckler’s picture

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.

TechNikh’s picture

I found the test module very useful for different version code. http://cgit.drupalcode.org/libraries/tree/tests/modules/libraries_test_m...