Commit f6b150aa authored by alexpott's avatar alexpott

Issue #1396892 by larowlan, nick_schuch | quicksketch: Fixed...

Issue #1396892 by larowlan, nick_schuch | quicksketch: Fixed drupal_get_library() may break JavaScript library path by clobbering it with the library version number.
parent 87163be3
......@@ -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'];
}
}
......
......@@ -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.');
}
/**
......
......@@ -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;
}
......
/**
* 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()
*/
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