Commit 9a8caf44 authored by catch's avatar catch

Issue #1813186 by nod_: Integrate scripts/stylesheets from info/layout files with libraries.

parent 8f028bb7
......@@ -211,32 +211,28 @@ function _drupal_theme_initialize($theme, $base_theme = array()) {
drupal_render($css);
// Do basically the same as the above for scripts
$final_scripts = array();
$final_libraries = array();
// Grab scripts from base theme
foreach ($base_theme as $base) {
if (!empty($base->scripts)) {
foreach ($base->scripts as $name => $script) {
$final_scripts[$name] = $script;
if (!empty($base->libraries)) {
foreach ($base->libraries as $library) {
$final_libraries[] = $library;
}
}
}
// Add scripts used by this theme.
if (!empty($theme->scripts)) {
foreach ($theme->scripts as $name => $script) {
$final_scripts[$name] = $script;
if (!empty($theme->libraries)) {
foreach ($theme->libraries as $library) {
$final_libraries[] = $library;
}
}
// Add scripts used by this theme.
$js = array();
foreach ($final_scripts as $script) {
$js['#attached']['js'][] = array(
'data' => $script,
'group' => JS_THEME,
'every_page' => TRUE,
);
foreach ($final_libraries as $library) {
$js['#attached']['library'][] = $library;
}
drupal_render($js);
......
......@@ -206,8 +206,8 @@ public function listInfo() {
$theme->stylesheets[$media][$stylesheet] = $path;
}
}
foreach ($theme->info['scripts'] as $script => $path) {
$theme->scripts[$script] = $path;
foreach ($theme->info['libraries'] as $library => $name) {
$theme->libraries[$library] = $name;
}
if (isset($theme->info['engine'])) {
$theme->engine = $theme->info['engine'];
......@@ -265,7 +265,7 @@ public function rebuildThemeData() {
'screenshot' => 'screenshot.png',
'php' => DRUPAL_MINIMUM_PHP,
'stylesheets' => array(),
'scripts' => array(),
'libraries' => array(),
);
$sub_themes = array();
......@@ -294,10 +294,9 @@ public function rebuildThemeData() {
$theme->prefix = $engines[$engine]->getName();
}
// Prefix stylesheets, scripts, and screenshot with theme path.
// Prefix stylesheets and screenshot with theme path.
$path = $theme->getPath();
$theme->info['stylesheets'] = $this->themeInfoPrefixPath($theme->info['stylesheets'], $path);
$theme->info['scripts'] = $this->themeInfoPrefixPath($theme->info['scripts'], $path);
if (!empty($theme->info['screenshot'])) {
$theme->info['screenshot'] = $path . '/' . $theme->info['screenshot'];
}
......@@ -338,7 +337,7 @@ public function rebuildThemeData() {
*
* This helper function is mainly used to prefix all array values of an
* .info.yml file property with a single given path (to the module or theme);
* e.g., to prefix all values of the 'stylesheets' or 'scripts' properties
* e.g., to prefix all values of the 'stylesheets' properties
* with the file path to the defining module/theme.
*
* @param array $info
......
......@@ -196,8 +196,8 @@ public function testEnableAndListInfo() {
'css/colors.css',
),
),
'scripts' => array(
'example' => 'theme.js',
'libraries' => array(
'example/theme',
),
'engine' => 'twig',
'base theme' => 'stark',
......@@ -207,7 +207,7 @@ public function testEnableAndListInfo() {
$this->assertCount(1, $list_info);
$this->assertEquals($this->themeHandler->systemList['bartik']->info['stylesheets'], $list_info['bartik']->stylesheets);
$this->assertEquals($this->themeHandler->systemList['bartik']->scripts, $list_info['bartik']->scripts);
$this->assertEquals($this->themeHandler->systemList['bartik']->libraries, $list_info['bartik']->libraries);
$this->assertEquals('twig', $list_info['bartik']->engine);
$this->assertEquals('stark', $list_info['bartik']->base_theme);
$this->assertEquals(0, $list_info['bartik']->status);
......@@ -219,7 +219,7 @@ public function testEnableAndListInfo() {
'style.css',
),
),
'scripts' => array(),
'libraries' => array(),
);
$this->themeHandler->systemList['seven']->status = 1;
......@@ -274,7 +274,7 @@ public function testRebuildThemeData() {
$this->assertEquals('twig', $info->prefix);
$this->assertEquals('twig', $info->info['engine']);
$this->assertEquals(array(), $info->info['scripts']);
$this->assertEquals(array(), $info->info['libraries']);
// Ensure that the css paths are set with the proper prefix.
$this->assertEquals(array(
......
......@@ -4,13 +4,11 @@ description: 'A flexible, recolorable theme with many regions and a responsive,
package: Core
version: VERSION
core: 8.x
libraries:
- bartik/base
stylesheets:
all:
- css/layout.css
- css/style.css
- css/colors.css
print:
- css/print.css
ckeditor_stylesheets:
- css/ckeditor-iframe.css
regions:
......
base:
version: VERSION
css:
theme:
css/layout.css: {}
css/style.css: {}
css/print.css: { media: print }
maintenance_page:
version: VERSION
css:
......
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