diff --git a/core/includes/common.inc b/core/includes/common.inc index 358a59a..d6ea447 100644 --- a/core/includes/common.inc +++ b/core/includes/common.inc @@ -2761,6 +2761,17 @@ function drupal_add_library($module, $name, $every_page = NULL) { ); foreach (array('js', 'css') as $type) { foreach ($elements['#attached'][$type] as $data => $options) { + // If the value is not an array, it's a filename and passed as first + // (and only) argument. + if (!is_array($options)) { + // Remove the previous array key, use the filename as key for a new + // entry. + unset($elements['#attached'][$type][$data]); + $data = $options; + $elements['#attached'][$type][$data] = array(); + $options = array(); + } + // Apply the JS_LIBRARY group if it isn't explicitly given. if ($type == 'js' && !isset($options['group'])) { $elements['#attached']['js'][$data]['group'] = JS_LIBRARY; 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 783eab2..128dc30 100644 --- a/core/modules/system/lib/Drupal/system/Tests/Common/JavaScriptTest.php +++ b/core/modules/system/lib/Drupal/system/Tests/Common/JavaScriptTest.php @@ -480,9 +480,10 @@ function testLibraryRender() { $this->assertTrue(strpos($styles, 'core/assets/vendor/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'; + $path = drupal_get_path('module', 'common_test') . '/js/shorthand.js?v=0.8.3.37'; $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.'); + $this->assertEqual(substr_count($scripts, 'shorthand.js'), 1, 'Shorthand JavaScript file only added once.'); } /**