Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
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.
Comment | File | Size | Author |
---|---|---|---|
#5 | 1953260-4-libraries-get-version-docs.patch | 907 bytes | tstoeckler |
Comments
Comment #1
jemond CreditAttribution: jemond commentedI can confirm this patch fixes the issue. Updated patch attach: Same patch, just corrected filename.
Comment #2
tstoecklerWell, 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?
Comment #3
corbacho CreditAttribution: corbacho commentedThis 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:
Maybe we could add that 'path' is not taken into account?
Comment #4
tstoecklerHere is a patch to improve the documentation.
Comment #5
tstoecklerOops, wrong patch. Here we go.
Comment #6
tstoecklerCommitted to 7.x-2.x (http://drupalcode.org/project/libraries.git/commit/5d7a8da2940595ed1b5b3...) and 7.x-3.x (http://drupalcode.org/project/libraries.git/commit/2aad17a420ac6c2f03752...).