diff --git a/core/includes/common.inc b/core/includes/common.inc index 35056deb34e6012940d53feb661695da8a734fd3..fbacae60b96aac5e64e90137908edd2779bd50b8 100644 --- a/core/includes/common.inc +++ b/core/includes/common.inc @@ -4576,6 +4576,13 @@ function drupal_get_library($module, $name = NULL) { // Add default elements to allow for easier processing. $module_libraries[$key] += array('dependencies' => array(), 'js' => array(), 'css' => array()); foreach ($module_libraries[$key]['js'] as $file => $options) { + if (is_scalar($options)) { + // The JavaScript or CSS file has been specified in shorthand + // format, without an array of options. In this case $options is the + // filename. + $file = $options; + $options = array(); + } $module_libraries[$key]['js'][$file]['version'] = $module_libraries[$key]['version']; } } diff --git a/core/modules/system/lib/Drupal/system/Tests/Common/JavaScriptTest.php b/core/modules/system/lib/Drupal/system/Tests/Common/JavaScriptTest.php index 3c54ad4c8eb5b479315b16b3bbc9555c3bb8cfbd..89cba50fc3d527d5df1ae8e05cf49c942c01876d 100644 --- a/core/modules/system/lib/Drupal/system/Tests/Common/JavaScriptTest.php +++ b/core/modules/system/lib/Drupal/system/Tests/Common/JavaScriptTest.php @@ -477,6 +477,11 @@ function testLibraryRender() { $styles = drupal_get_css(); $this->assertTrue(strpos($scripts, 'core/misc/farbtastic/farbtastic.js'), 'JavaScript of library was added to the page.'); $this->assertTrue(strpos($styles, 'core/misc/farbtastic/farbtastic.css'), 'Stylesheet of library was added to the page.'); + + $result = drupal_add_library('common_test', 'shorthand.plugin'); + $path = drupal_get_path('module', 'common_test') . '/js/shorthand.js'; + $scripts = drupal_get_js(); + $this->assertTrue(strpos($scripts, $path), 'JavaScript specified in hook_library_info() using shorthand format (without any options) was added to the page.'); } /** diff --git a/core/modules/system/tests/modules/common_test/common_test.module b/core/modules/system/tests/modules/common_test/common_test.module index f932f0fd542d7ccbf33b50ef5a6829157648a1d4..203ead225a53aef90d79e04554edd279b4bf4b72 100644 --- a/core/modules/system/tests/modules/common_test/common_test.module +++ b/core/modules/system/tests/modules/common_test/common_test.module @@ -290,6 +290,21 @@ function common_test_library_info() { array('system', 'jquery'), ), ); + // Nominate a library using the shorthand format, where no options are given, + // just the file name. + $libraries['shorthand.plugin'] = array( + 'title' => 'Shorthand Plugin', + 'website' => 'http://www.example.com/', + 'version' => '0.8.3.37', + 'js' => array( + // Here we attach the JavaScript file using the shorthand format, only + // the file name is given, no options. + drupal_get_path('module', 'common_test') . '/js/shorthand.js', + ), + 'dependencies' => array( + array('system', 'jquery'), + ), + ); return $libraries; } diff --git a/core/modules/system/tests/modules/common_test/js/shorthand.js b/core/modules/system/tests/modules/common_test/js/shorthand.js new file mode 100644 index 0000000000000000000000000000000000000000..737d9d7f03b48102e80bd2b4e038a26ebc008834 --- /dev/null +++ b/core/modules/system/tests/modules/common_test/js/shorthand.js @@ -0,0 +1,9 @@ +/** + * JavaScript file for the 'Shorthand' plugin. + * + * This file is intentionally blank. It is used to test that nominating + * JavaScript (and CSS) files in the shorthand format using hook_library_info(). + * + * @see common_test_library_info() + * @see Drupal/system/Tests/Common/JavaScriptTest::testLibraryRender() + */