According to the hook_libraries_info() documentation:

 *   - path: (optional) A relative path from the directory of the library to the
 *     actual library. Only required if the extracted download package contains
 *     the actual library files in a sub-directory.

Unfortunately, libraries_get_version() doesn't take this into account. This means that if you need to pull the version from the actual library file, you can't unless it's in the top level of the library path.

The attached patch updates libraries_get_version() to use the $library['path'] variable if set.

use-library-path-if-set.patch633 bytesbrianV
PASSED: [[SimpleTest]]: [MySQL] 135 pass(es). View
#5 1953260-4-libraries-get-version-docs.patch907 byteststoeckler
PASSED: [[SimpleTest]]: [MySQL] 152 pass(es). View
Members fund testing for the Drupal project. Drupal Association Learn more


jemond’s picture

I can confirm this patch fixes the issue. Updated patch attach: Same patch, just corrected filename.

tstoeckler’s picture

Well, this currently works as designed. Many libraries provide a separate CHANGELOG.txt or README.txt which contains the version, but is not inside of the $library['path']. While not 100% beatiful in your use-case, it wouldn't be a problem to simply duplicate the $library['path'] part in $options['file'], would it?

corbacho’s picture

This bug also bite me. But also I understand your logic. "it's not a bug, it's a feature" :D

So instead of fixing the code, at least we could make the documentation more clear. Currently it says:

"file: The filename to parse for the version, relative to the library path. For example: 'docs/changelog.txt'

Maybe we could add that 'path' is not taken into account?

tstoeckler’s picture

Title: libraries_get_version() doesn't take $libraries['path'] into account » Improve documentation of libraries_get_version() 'path' option.
Issue summary: View changes

Here is a patch to improve the documentation.

tstoeckler’s picture

907 bytes
PASSED: [[SimpleTest]]: [MySQL] 152 pass(es). View

Oops, wrong patch. Here we go.

tstoeckler’s picture

Status: Fixed » Closed (fixed)

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