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.
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;
}
Comment | File | Size | Author |
---|---|---|---|
#9 | 2046919-9-libraries-version-docs.patch | 859 bytes | tstoeckler |
Comments
Comment #1
tstoecklerHmmm, it's even a bit more complicated than that, because 'version callback' defaults to 'libraries_get_version'. Does the attached patch clarify the situation?
Comment #2
tstoecklerWait, I messed that up. How's this one?
Comment #4
tstoecklerLet's try this again.
Comment #5
tstoecklerCommitted. Thanks for the report!
7.x-2.x: http://drupalcode.org/project/libraries.git/commit/ddc9cc64868e4fef5b3ce...
7.x-3.x: http://drupalcode.org/project/libraries.git/commit/fbfc8cbf2975d981b1e98...
Comment #6
tstoecklerComment #8
joachim CreditAttribution: joachim commentedThe 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.
Comment #9
tstoecklerCommitted attached patch to 7.x-2.x (http://drupalcode.org/project/libraries.git/commit/04283da124de08aaa2b28...) and 7.x-3.x (http://drupalcode.org/project/libraries.git/commit/a6db550da10a223519342...).
Hope that makes it sufficiently clear.
Comment #11
TechNikh CreditAttribution: TechNikh commentedI found the test module very useful for different version code. http://cgit.drupalcode.org/libraries/tree/tests/modules/libraries_test_m...