Commit c365e82b authored by Tobias Stoeckler's avatar Tobias Stoeckler

#919632 by tstoeckler: Add example library info file for testing purposes.

parent 0b9ee13e
......@@ -6,6 +6,7 @@ Libraries x.x-x.x, xxxx-xx-xx
Libraries 7.x-1.x, xxxx-xx-xx
-----------------------------
#919632 by tstoeckler: Add example library info file for testing purposes.
#719896 by tstoeckler, sun: Documentation clean-up and tests improvement.
#542940 by sun: Added initial Drush integration file.
#719896 by tstoeckler, sun: Improved library detection and library loading.
......
......@@ -330,3 +330,26 @@ function hook_libraries_info_alter(&$libraries) {
);
$libraries['php_spellchecker']['integration files']['example_module'] = $files;
}
/**
* Specify paths to look for library info files.
*
* Libraries API looks in the following directories for library info files by
* default:
* - libraries
* - profiles/$profile/libraries
* - sites/all/libraries
* - sites/$site/libraries
* This hook allows you to specify additional locations to look for library info
* files. This should only be used for modules that declare many libraries.
* Modules that only implement a few libraries should implement
* hook_libraries_info().
*
* @return
* An array of paths.
*/
function hook_libraries_paths() {
// Taken from the Libraries test module, which needs to specify the path to
// the test library.
return array(drupal_get_path('module', 'libraries_test') . '/example');
}
......@@ -112,6 +112,49 @@ function libraries_get_libraries() {
return $directories;
}
/**
* Looks for library info files.
*
* This function scans the following directories for info files:
* - libraries
* - profiles/$profilename/libraries
* - sites/all/libraries
* - sites/$sitename/libraries
* - any directories specified via hook_libraries_info_file_paths()
*
* @return
* An array of info files, keyed by library name. The values are the paths of
* the files.
*/
function libraries_info_files() {
global $profile;
if (!isset($profile)) {
$profile = variable_get('install_profile', 'default');
}
$config = conf_path();
// Build a list of directories.
$directories = module_invoke_all('libraries_info_file_paths');
$directories[] = 'libraries';
$directories[] = "libraries/$profile/libraries";
$directories[] = 'sites/all/libraries';
$directories[] = "sites/$config/libraries";
// Scan for info files.
$files = array();
foreach ($directories as $dir) {
$files += file_scan_directory($dir, '/[a-z[a-z0-9_]+.info/', array(
'key' => 'name',
'recurse' => FALSE,
));
}
foreach ($files as &$file) {
$file = $file->uri;
}
return $files;
}
/**
* Returns information about registered libraries.
*
......@@ -140,23 +183,31 @@ function libraries_info($library = NULL) {
foreach (module_invoke($module, 'libraries_info') as $name => $properties) {
$properties['module'] = $module;
$properties['name'] = $name;
$properties += array(
'title' => $name,
'vendor url' => '',
'download url' => '',
'path' => '',
'version callback' => 'libraries_get_version',
'version arguments' => array(),
'files' => array(),
'variants' => array(),
'versions' => array(),
'integration files' => array(),
);
$libraries[$name] = $properties;
}
}
// Gather information from .info files.
foreach (libraries_info_files() as $name => $path) {
$file = "$path/$name.info";
$libraries[$name] = drupal_parse_info_file($file);
}
// Provide defaults.
foreach ($libraries as $name => &$properties) {
$properties += array(
'title' => $name,
'vendor url' => '',
'download url' => '',
'path' => '',
'version callback' => 'libraries_get_version',
'version arguments' => array(),
'files' => array(),
'variants' => array(),
'versions' => array(),
'integration files' => array(),
);
}
// Allow modules to alter the registered libraries.
drupal_alter('libraries_info', $libraries);
}
......
; $Id$
; This is an example info file for a library used for testing purposes. It
; contains no actual library information, but, since it is named example.info,
; if Libraries API detects a library named 'example', we know that this file was
; properly detected.
......@@ -26,6 +26,22 @@ class LibrariesTestCase extends DrupalWebTestCase {
* @todo Better method name(s); split into detection/loading/overloading/etc.
*/
public function testLibraries() {
// Test a library specified with an .info file gets detected.
$library = libraries_info('example');
$expected = array(
'title' => 'example',
'vendor url' => '',
'download url' => '',
'path' => '',
'version callback' => 'libraries_get_version',
'version arguments' => array(),
'files' => array(),
'variants' => array(),
'versions' => array(),
'integration files' => array(),
);
$this->assertEqual($library, $expected, 'Library specified with an .info file found');
// Test missing library.
$library = libraries_info('example_missing');
libraries_detect_library($library);
......
......@@ -287,6 +287,13 @@ function libraries_test_libraries_info() {
return $libraries;
}
/**
* Implements hook_libraries_info_file_paths()
*/
function libraries_test_libraries_info_file_paths() {
return array(drupal_get_path('module', 'libraries_test') . '/example');
}
/**
* Gets the version of an example library.
*
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment