Issue #1813186 by nod_: Integrate scripts/stylesheets from info/layout files with libraries.
parent
a7fccaae12
commit
4e5b0480f4
|
@ -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;
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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(
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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:
|
||||
|
|
Loading…
Reference in New Issue