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

8.0.x
Nathaniel Catchpole 2014-04-01 14:10:47 +01:00
parent a7fccaae12
commit 4e5b0480f4
5 changed files with 38 additions and 30 deletions

View File

@ -210,35 +210,31 @@ function _drupal_theme_initialize($theme, $base_theme = array()) {
}
drupal_render($css);
// Do basically the same as the above for scripts
$final_scripts = array();
// Do basically the same as the above for libraries
$final_libraries = array();
// Grab scripts from base theme
// Grab libraries 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;
// Add libraries used by this theme.
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,
);
// Add libraries used by this theme.
$libraries = array();
foreach ($final_libraries as $library) {
$libraries['#attached']['library'][] = $library;
}
drupal_render($js);
drupal_render($libraries);
$theme_engine = NULL;

View File

@ -206,8 +206,8 @@ class ThemeHandler implements ThemeHandlerInterface {
$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 @@ class ThemeHandler implements ThemeHandlerInterface {
'screenshot' => 'screenshot.png',
'php' => DRUPAL_MINIMUM_PHP,
'stylesheets' => array(),
'scripts' => array(),
'libraries' => array(),
);
$sub_themes = array();
@ -294,10 +294,9 @@ class ThemeHandler implements ThemeHandlerInterface {
$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 @@ class ThemeHandler implements ThemeHandlerInterface {
*
* 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

View File

@ -196,8 +196,8 @@ class ThemeHandlerTest extends UnitTestCase {
'css/colors.css',
),
),
'scripts' => array(
'example' => 'theme.js',
'libraries' => array(
'example/theme',
),
'engine' => 'twig',
'base theme' => 'stark',
@ -207,7 +207,7 @@ class ThemeHandlerTest extends UnitTestCase {
$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 @@ class ThemeHandlerTest extends UnitTestCase {
'style.css',
),
),
'scripts' => array(),
'libraries' => array(),
);
$this->themeHandler->systemList['seven']->status = 1;
@ -274,7 +274,7 @@ class ThemeHandlerTest extends UnitTestCase {
$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(

View File

@ -4,6 +4,10 @@ description: 'A flexible, recolorable theme with many regions and a responsive,
package: Core
version: VERSION
core: 8.x
# @todo use library version once color module is fixed #2228745
#libraries:
# - bartik/base
#
stylesheets:
all:
- css/layout.css

View File

@ -1,3 +1,12 @@
base:
version: VERSION
css:
theme:
css/layout.css: {}
css/style.css: {}
css/colors.css: {}
css/print.css: { media: print }
maintenance_page:
version: VERSION
css: