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); drupal_render($css);
// Do basically the same as the above for scripts // Do basically the same as the above for libraries
$final_scripts = array(); $final_libraries = array();
// Grab scripts from base theme // Grab libraries from base theme
foreach ($base_theme as $base) { foreach ($base_theme as $base) {
if (!empty($base->scripts)) { if (!empty($base->libraries)) {
foreach ($base->scripts as $name => $script) { foreach ($base->libraries as $library) {
$final_scripts[$name] = $script; $final_libraries[] = $library;
} }
} }
} }
// Add scripts used by this theme. // Add libraries used by this theme.
if (!empty($theme->scripts)) { if (!empty($theme->libraries)) {
foreach ($theme->scripts as $name => $script) { foreach ($theme->libraries as $library) {
$final_scripts[$name] = $script; $final_libraries[] = $library;
} }
} }
// Add scripts used by this theme. // Add libraries used by this theme.
$js = array(); $libraries = array();
foreach ($final_scripts as $script) { foreach ($final_libraries as $library) {
$js['#attached']['js'][] = array( $libraries['#attached']['library'][] = $library;
'data' => $script,
'group' => JS_THEME,
'every_page' => TRUE,
);
} }
drupal_render($js); drupal_render($libraries);
$theme_engine = NULL; $theme_engine = NULL;

View File

@ -206,8 +206,8 @@ class ThemeHandler implements ThemeHandlerInterface {
$theme->stylesheets[$media][$stylesheet] = $path; $theme->stylesheets[$media][$stylesheet] = $path;
} }
} }
foreach ($theme->info['scripts'] as $script => $path) { foreach ($theme->info['libraries'] as $library => $name) {
$theme->scripts[$script] = $path; $theme->libraries[$library] = $name;
} }
if (isset($theme->info['engine'])) { if (isset($theme->info['engine'])) {
$theme->engine = $theme->info['engine']; $theme->engine = $theme->info['engine'];
@ -265,7 +265,7 @@ class ThemeHandler implements ThemeHandlerInterface {
'screenshot' => 'screenshot.png', 'screenshot' => 'screenshot.png',
'php' => DRUPAL_MINIMUM_PHP, 'php' => DRUPAL_MINIMUM_PHP,
'stylesheets' => array(), 'stylesheets' => array(),
'scripts' => array(), 'libraries' => array(),
); );
$sub_themes = array(); $sub_themes = array();
@ -294,10 +294,9 @@ class ThemeHandler implements ThemeHandlerInterface {
$theme->prefix = $engines[$engine]->getName(); $theme->prefix = $engines[$engine]->getName();
} }
// Prefix stylesheets, scripts, and screenshot with theme path. // Prefix stylesheets and screenshot with theme path.
$path = $theme->getPath(); $path = $theme->getPath();
$theme->info['stylesheets'] = $this->themeInfoPrefixPath($theme->info['stylesheets'], $path); $theme->info['stylesheets'] = $this->themeInfoPrefixPath($theme->info['stylesheets'], $path);
$theme->info['scripts'] = $this->themeInfoPrefixPath($theme->info['scripts'], $path);
if (!empty($theme->info['screenshot'])) { if (!empty($theme->info['screenshot'])) {
$theme->info['screenshot'] = $path . '/' . $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 * 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); * .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. * with the file path to the defining module/theme.
* *
* @param array $info * @param array $info

View File

@ -196,8 +196,8 @@ class ThemeHandlerTest extends UnitTestCase {
'css/colors.css', 'css/colors.css',
), ),
), ),
'scripts' => array( 'libraries' => array(
'example' => 'theme.js', 'example/theme',
), ),
'engine' => 'twig', 'engine' => 'twig',
'base theme' => 'stark', 'base theme' => 'stark',
@ -207,7 +207,7 @@ class ThemeHandlerTest extends UnitTestCase {
$this->assertCount(1, $list_info); $this->assertCount(1, $list_info);
$this->assertEquals($this->themeHandler->systemList['bartik']->info['stylesheets'], $list_info['bartik']->stylesheets); $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('twig', $list_info['bartik']->engine);
$this->assertEquals('stark', $list_info['bartik']->base_theme); $this->assertEquals('stark', $list_info['bartik']->base_theme);
$this->assertEquals(0, $list_info['bartik']->status); $this->assertEquals(0, $list_info['bartik']->status);
@ -219,7 +219,7 @@ class ThemeHandlerTest extends UnitTestCase {
'style.css', 'style.css',
), ),
), ),
'scripts' => array(), 'libraries' => array(),
); );
$this->themeHandler->systemList['seven']->status = 1; $this->themeHandler->systemList['seven']->status = 1;
@ -274,7 +274,7 @@ class ThemeHandlerTest extends UnitTestCase {
$this->assertEquals('twig', $info->prefix); $this->assertEquals('twig', $info->prefix);
$this->assertEquals('twig', $info->info['engine']); $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. // Ensure that the css paths are set with the proper prefix.
$this->assertEquals(array( $this->assertEquals(array(

View File

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