summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAngie Byron <webchick@24967.no-reply.drupal.org>2010-12-15 04:21:39 +0000
committerAngie Byron <webchick@24967.no-reply.drupal.org>2010-12-15 04:21:39 +0000
commitde5b89a072216b1b4f8fd3425bab504e0a88aee5 (patch)
treefcc7c251279ba0738734a157b9547d6da8126a97
parentc2ec8e397a1479b28a02af79af4b75390ad57c2e (diff)
downloadbrdo-de5b89a072216b1b4f8fd3425bab504e0a88aee5.tar.gz
brdo-de5b89a072216b1b4f8fd3425bab504e0a88aee5.tar.bz2
#714382 by Rob Loach, sun: Fixed Can't retrieve all libraries of a module
-rw-r--r--includes/common.inc22
-rw-r--r--modules/simpletest/tests/common.test20
2 files changed, 34 insertions, 8 deletions
diff --git a/includes/common.inc b/includes/common.inc
index 889276086..d400c033d 100644
--- a/includes/common.inc
+++ b/includes/common.inc
@@ -4523,10 +4523,14 @@ function drupal_add_library($module, $name, $every_page = NULL) {
*
* @param $module
* The name of a module that registered a library.
- * @param $library
- * The name of a registered library.
+ * @param $name
+ * (optional) The name of a registered library to retrieve. By default, all
+ * libraries registered by $module are returned.
+ *
* @return
- * The definition of the requested library, if existent, or FALSE.
+ * The definition of the requested library, if $name was passed and it exists,
+ * or FALSE if it does not exist. If no $name was passed, an associative array
+ * of libraries registered by $module is returned (which may be empty).
*
* @see drupal_add_library()
* @see hook_library()
@@ -4535,7 +4539,7 @@ function drupal_add_library($module, $name, $every_page = NULL) {
* @todo The purpose of drupal_get_*() is completely different to other page
* requisite API functions; find and use a different name.
*/
-function drupal_get_library($module, $name) {
+function drupal_get_library($module, $name = NULL) {
$libraries = &drupal_static(__FUNCTION__, array());
if (!isset($libraries[$module])) {
@@ -4558,11 +4562,13 @@ function drupal_get_library($module, $name) {
}
$libraries[$module] = $module_libraries;
}
- if (empty($libraries[$module][$name])) {
- $libraries[$module][$name] = FALSE;
+ if (isset($name)) {
+ if (!isset($libraries[$module][$name])) {
+ $libraries[$module][$name] = FALSE;
+ }
+ return $libraries[$module][$name];
}
-
- return $libraries[$module][$name];
+ return $libraries[$module];
}
/**
diff --git a/modules/simpletest/tests/common.test b/modules/simpletest/tests/common.test
index 9bbbeabfa..ca29e11f8 100644
--- a/modules/simpletest/tests/common.test
+++ b/modules/simpletest/tests/common.test
@@ -1424,6 +1424,26 @@ class JavaScriptTestCase extends DrupalWebTestCase {
}
/**
+ * Tests retrieval of libraries via drupal_get_library().
+ */
+ function testGetLibrary() {
+ // Retrieve all libraries registered by a module.
+ $libraries = drupal_get_library('common_test');
+ $this->assertTrue(isset($libraries['farbtastic']), t('Retrieved all module libraries.'));
+ // Retrieve all libraries for a module not implementing hook_library().
+ // Note: This test installs Locale module.
+ $libraries = drupal_get_library('locale');
+ $this->assertEqual($libraries, array(), t('Retrieving libraries from a module not implementing hook_library() returns an emtpy array.'));
+
+ // Retrieve a specific library by module and name.
+ $farbtastic = drupal_get_library('common_test', 'farbtastic');
+ $this->assertEqual($farbtastic['version'], '5.3', t('Retrieved a single library.'));
+ // Retrieve a non-existing library by module and name.
+ $farbtastic = drupal_get_library('common_test', 'foo');
+ $this->assertIdentical($farbtastic, FALSE, t('Retrieving a non-existing library returns FALSE.'));
+ }
+
+ /**
* Tests that the query string remains intact when adding JavaScript files
* that have query string parameters.
*/