Commit 0bfb32b5 authored by catch's avatar catch

git commit -m 'Issue #2377397 by Wim Leers, alexpott: Themes should use...

git commit -m 'Issue #2377397 by Wim Leers, alexpott: Themes should use libraries, not individual stylesheets'
parent d3f58a52
......@@ -396,12 +396,6 @@ public function listInfo() {
* {@inheritdoc}
*/
public function addTheme(Extension $theme) {
// @todo Remove this 100% unnecessary duplication of properties.
foreach ($theme->info['stylesheets'] as $media => $stylesheets) {
foreach ($stylesheets as $stylesheet => $path) {
$theme->stylesheets[$media][$stylesheet] = $path;
}
}
foreach ($theme->info['libraries'] as $library => $name) {
$theme->libraries[$library] = $name;
}
......@@ -471,7 +465,6 @@ public function rebuildThemeData() {
'features' => $this->defaultFeatures,
'screenshot' => 'screenshot.png',
'php' => DRUPAL_MINIMUM_PHP,
'stylesheets' => array(),
'libraries' => array(),
);
......@@ -507,11 +500,9 @@ public function rebuildThemeData() {
$theme->prefix = $engines[$engine]->getName();
}
// Prefix stylesheets and screenshot with theme path.
$path = $theme->getPath();
$theme->info['stylesheets'] = $this->themeInfoPrefixPath($theme->info['stylesheets'], $path);
// Prefix screenshot with theme path.
if (!empty($theme->info['screenshot'])) {
$theme->info['screenshot'] = $path . '/' . $theme->info['screenshot'];
$theme->info['screenshot'] = $theme->getPath() . '/' . $theme->info['screenshot'];
}
$files[$key] = $theme->getPathname();
......@@ -555,41 +546,6 @@ public function rebuildThemeData() {
return $themes;
}
/**
* Prefixes all values in an .info.yml file array with a given path.
*
* 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' properties
* with the file path to the defining module/theme.
*
* @param array $info
* A nested array of data of an .info.yml file to be processed.
* @param string $path
* A file path to prepend to each value in $info.
*
* @return array
* The $info array with prefixed values.
*
* @see _system_rebuild_module_data()
* @see self::rebuildThemeData()
*/
protected function themeInfoPrefixPath(array $info, $path) {
foreach ($info as $key => $value) {
// Recurse into nested values until we reach the deepest level.
if (is_array($value)) {
$info[$key] = $this->themeInfoPrefixPath($info[$key], $path);
}
// Unset the original value's key and set the new value with prefix, using
// the original value as key, so original values can still be looked up.
else {
unset($info[$key]);
$info[$value] = $path . '/' . $value;
}
}
return $info;
}
/**
* {@inheritdoc}
*/
......
......@@ -59,13 +59,6 @@ class ActiveTheme {
*/
protected $extension;
/**
* The provided stylesheet of the theme.
*
* @var array
*/
protected $styleSheets;
/**
* The stylesheets which are set to be removed by the theme.
*
......@@ -98,7 +91,6 @@ public function __construct(array $values) {
$this->path = $values['path'];
$this->engine = $values['engine'];
$this->owner = $values['owner'];
$this->styleSheets = $values['stylesheets'];
$this->styleSheetsRemove = $values['stylesheets_remove'];
$this->styleSheetsOverride = $values['stylesheets_override'];
$this->libraries = $values['libraries'];
......@@ -162,15 +154,6 @@ public function getLibraries() {
return $this->libraries;
}
/**
* Returns the stylesheets provided by the theme.
*
* @return mixed
*/
public function getStyleSheets() {
return $this->styleSheets;
}
/**
* Returns the overridden stylesheets by the theme.
*
......
......@@ -154,22 +154,13 @@ public function getActiveTheme(Extension $theme, array $base_themes = []) {
// Prepare stylesheets from this theme as well as all ancestor themes.
// We work it this way so that we can have child themes override parent
// theme stylesheets easily.
$values['stylesheets'] = array();
// CSS file basenames to override, pointing to the final, overridden filepath.
$values['stylesheets_override'] = array();
// CSS file basenames to remove.
$values['stylesheets_remove'] = array();
// Grab stylesheets from base theme.
$final_stylesheets = array();
foreach ($base_themes as $base) {
if (!empty($base->stylesheets)) {
foreach ($base->stylesheets as $media => $stylesheets) {
foreach ($stylesheets as $name => $stylesheet) {
$final_stylesheets[$media][$name] = $stylesheet;
}
}
}
$base_theme_path = $base->getPath();
if (!empty($base->info['stylesheets-remove'])) {
foreach ($base->info['stylesheets-remove'] as $basename) {
......@@ -185,13 +176,6 @@ public function getActiveTheme(Extension $theme, array $base_themes = []) {
}
// Add stylesheets used by this theme.
if (!empty($theme->stylesheets)) {
foreach ($theme->stylesheets as $media => $stylesheets) {
foreach ($stylesheets as $name => $stylesheet) {
$final_stylesheets[$media][$name] = $stylesheet;
}
}
}
if (!empty($theme->info['stylesheets-remove'])) {
foreach ($theme->info['stylesheets-remove'] as $basename) {
$values['stylesheets_remove'][$basename] = $theme_path . '/' . $basename;
......@@ -212,9 +196,6 @@ public function getActiveTheme(Extension $theme, array $base_themes = []) {
}
}
// And now add the stylesheets properly.
$values['stylesheets'] = $final_stylesheets;
// Do basically the same as the above for libraries
$values['libraries'] = array();
......
......@@ -30,6 +30,12 @@ drupal.content_types:
- core/drupal
- core/drupal.form
form:
version: VERSION
css:
layout:
css/node.module.css: {}
drupal.node.admin:
version: VERSION
css:
......
......@@ -205,6 +205,8 @@ public function form(array $form, FormStateInterface $form_state) {
$form['sticky']['#group'] = 'options';
}
$form['#attached']['library'][] = 'node/form';
return $form;
}
......
......@@ -528,20 +528,11 @@ function system_page_attachments(array &$page) {
$page['#attached']['library'][] = 'system/admin';
}
// Attach libraries and CSS used by this theme.
// Attach libraries used by this theme.
$active_theme = \Drupal::theme()->getActiveTheme();
foreach ($active_theme->getLibraries() as $library) {
$page['#attached']['library'][] = $library;
}
foreach ($active_theme->getStyleSheets() as $media => $stylesheets) {
foreach ($stylesheets as $stylesheet) {
$page['#attached']['css'][$stylesheet] = array(
'group' => CSS_AGGREGATE_THEME,
'every_page' => TRUE,
'media' => $media
);
}
}
// Attach favicon.
if (theme_get_setting('features.favicon')) {
......
......@@ -34,16 +34,10 @@ public function functionTemplateOverridden() {
* A render array containing custom stylesheets.
*/
public function testInfoStylesheets() {
$path = drupal_get_path('module', 'theme_test');
return array(
'#attached' => array(
'css' => array(
"$path/css/base-override.css",
"$path/css/base-override.sub-remove.css",
"$path/css/base-remove.css",
"$path/css/base-remove.sub-override.css",
"$path/css/sub-override.css",
"$path/css/sub-remove.css",
'library' => array(
'theme_test/theme_stylesheets_override_and_remove_test',
),
),
);
......
theme_stylesheets_override_and_remove_test:
version: VERSION
css:
base:
css/base-override.css: {}
css/base-override.sub-remove.css: {}
css/base-remove.css: {}
css/base-remove.sub-override.css: {}
css/sub-override.css: {}
css/sub-remove.css: {}
......@@ -3,11 +3,8 @@ type: theme
description: 'Test theme which acts as a base theme for other test subthemes.'
version: VERSION
core: 8.x
stylesheets:
all:
- base-add.css
- base-add.sub-override.css
- base-add.sub-remove.css
libraries:
- test_basetheme/global-styling
stylesheets-override:
- base-override.css
- base-override.sub-remove.css
......
global-styling:
version: VERSION
css:
base:
base-add.css: {}
base-add.sub-override.css: {}
base-add.sub-remove.css: {}
......@@ -4,9 +4,8 @@ description: 'Test theme which uses test_basetheme as the base theme.'
version: VERSION
core: 8.x
base theme: test_basetheme
stylesheets:
all:
- css/sub-add.css
libraries:
- test_subtheme/global-styling
stylesheets-override:
- css/sub-override.css
- css/base-add.sub-override.css
......
global-styling:
version: VERSION
css:
base:
css/sub-add.css: {}
......@@ -60,8 +60,8 @@ function hook_toolbar() {
'#weight' => 200,
// Custom CSS, JS or a library can be associated with the toolbar item.
'#attached' => array(
'css' => array(
drupal_get_path('module', 'search') . '/css/search.base.css',
'library' => array(
'search/global',
),
),
);
......
......@@ -170,45 +170,7 @@ public function testRebuildThemeData() {
$this->assertEquals('twig', $info->prefix);
$this->assertEquals('twig', $info->info['engine']);
$this->assertEquals(array(), $info->info['libraries']);
// Ensure that the css paths are set with the proper prefix.
$this->assertEquals(array(
'screen' => array(
'css/base/elements.css' => $this->root . '/core/themes/seven/css/base/elements.css',
'css/base/typography.css' => $this->root . '/core/themes/seven/css/base/typography.css',
'css/components/admin-list.css' => $this->root . '/core/themes/seven/css/components/admin-list.css',
'css/components/admin-options.css' => $this->root . '/core/themes/seven/css/components/admin-options.css',
'css/components/admin-panel.css' => $this->root . '/core/themes/seven/css/components/admin-panel.css',
'css/components/block-recent-content.css' => $this->root . '/core/themes/seven/css/components/block-recent-content.css',
'css/components/content-header.css' => $this->root . '/core/themes/seven/css/components/content-header.css',
'css/components/breadcrumb.css' => $this->root . '/core/themes/seven/css/components/breadcrumb.css',
'css/components/buttons.css' => $this->root . '/core/themes/seven/css/components/buttons.css',
'css/components/buttons.theme.css' => $this->root . '/core/themes/seven/css/components/buttons.theme.css',
'css/components/comments.css' => $this->root . '/core/themes/seven/css/components/comments.css',
'css/components/messages.css' => $this->root . '/core/themes/seven/css/components/messages.css',
'css/components/dropbutton.component.css' => $this->root . '/core/themes/seven/css/components/dropbutton.component.css',
'css/components/entity-meta.css' => $this->root . '/core/themes/seven/css/components/entity-meta.css',
'css/components/field-ui.css' => $this->root . '/core/themes/seven/css/components/field-ui.css',
'css/components/form.css' => $this->root . '/core/themes/seven/css/components/form.css',
'css/components/help.css' => $this->root . '/core/themes/seven/css/components/help.css',
'css/components/menus-and-lists.css' => $this->root . '/core/themes/seven/css/components/menus-and-lists.css',
'css/components/modules-page.css' => $this->root . '/core/themes/seven/css/components/modules-page.css',
'css/components/node.css' => $this->root . '/core/themes/seven/css/components/node.css',
'css/components/page-title.css' => $this->root . '/core/themes/seven/css/components/page-title.css',
'css/components/pager.css' => $this->root . '/core/themes/seven/css/components/pager.css',
'css/components/skip-link.css' => $this->root . '/core/themes/seven/css/components/skip-link.css',
'css/components/tables.css' => $this->root . '/core/themes/seven/css/components/tables.css',
'css/components/tabs.css' => $this->root . '/core/themes/seven/css/components/tabs.css',
'css/components/tour.theme.css' => $this->root . '/core/themes/seven/css/components/tour.theme.css',
'css/components/update-status.css' => $this->root . '/core/themes/seven/css/components/update-status.css',
'css/components/views-ui.css' => $this->root . '/core/themes/seven/css/components/views-ui.css',
'css/layout/layout.css' => $this->root . '/core/themes/seven/css/layout/layout.css',
'css/layout/node-add.css' => $this->root . '/core/themes/seven/css/layout/node-add.css',
'css/theme/appearance-page.css' => $this->root . '/core/themes/seven/css/theme/appearance-page.css',
),
), $info->info['stylesheets']);
$this->assertEquals($this->root . '/core/themes/seven/screenshot.png', $info->info['screenshot']);
$this->assertEquals(array('seven/global-styling'), $info->info['libraries']);
}
/**
......
......@@ -6,7 +6,7 @@ package: Core
version: VERSION
core: 8.x
libraries:
- bartik/base
- bartik/global-styling
ckeditor_stylesheets:
- css/ckeditor-iframe.css
regions:
......
base:
global-styling:
version: VERSION
css:
theme:
......@@ -14,4 +14,4 @@ maintenance_page:
css/maintenance-page.css: {}
dependencies:
- system/maintenance
- bartik/base
- bartik/global-styling
......@@ -7,39 +7,8 @@ tags: 'multi-column, fluid, responsive, sans-serif, accessible'
package: Core
version: VERSION
core: 8.x
stylesheets:
screen:
- css/base/elements.css
- css/base/typography.css
- css/components/admin-list.css
- css/components/admin-options.css
- css/components/admin-panel.css
- css/components/block-recent-content.css
- css/components/content-header.css
- css/components/breadcrumb.css
- css/components/buttons.css
- css/components/buttons.theme.css
- css/components/comments.css
- css/components/messages.css
- css/components/dropbutton.component.css
- css/components/entity-meta.css
- css/components/field-ui.css
- css/components/form.css
- css/components/help.css
- css/components/menus-and-lists.css
- css/components/modules-page.css
- css/components/node.css
- css/components/page-title.css
- css/components/pager.css
- css/components/skip-link.css
- css/components/tables.css
- css/components/tabs.css
- css/components/tour.theme.css
- css/components/update-status.css
- css/components/views-ui.css
- css/layout/layout.css
- css/layout/node-add.css
- css/theme/appearance-page.css
libraries:
- seven/global-styling
stylesheets-override:
- css/components/vertical-tabs.css
- css/components/jquery.ui.theme.css
......
global-styling:
version: VERSION
css:
base:
css/base/elements.css: {}
css/base/typography.css: {}
component:
css/components/admin-list.css: {}
css/components/admin-options.css: {}
css/components/admin-panel.css: {}
css/components/block-recent-content.css: {}
css/components/content-header.css: {}
css/components/breadcrumb.css: {}
css/components/buttons.css: {}
css/components/buttons.theme.css: {}
css/components/comments.css: {}
css/components/messages.css: {}
css/components/dropbutton.component.css: {}
css/components/entity-meta.css: {}
css/components/field-ui.css: {}
css/components/form.css: {}
css/components/help.css: {}
css/components/menus-and-lists.css: {}
css/components/modules-page.css: {}
css/components/node.css: {}
css/components/page-title.css: {}
css/components/pager.css: {}
css/components/skip-link.css: {}
css/components/tables.css: {}
css/components/tabs.css: {}
css/components/tour.theme.css: {}
css/components/update-status.css: {}
css/components/views-ui.css: {}
layout:
css/layout/layout.css: {}
theme:
css/theme/appearance-page.css: {}
node-form:
version: VERSION
css:
layout:
css/layout/node-add.css: {}
dependencies:
- node/form
maintenance-page:
version: VERSION
js:
......@@ -7,6 +53,7 @@ maintenance-page:
css/theme/maintenance-page.css: {}
dependencies:
- system/maintenance
- seven/global-styling
install-page:
version: VERSION
......
......@@ -167,7 +167,7 @@ function seven_form_node_form_alter(&$form, FormStateInterface $form_state) {
$node = $form_state->getFormObject()->getEntity();
$form['#theme'] = array('node_edit_form');
$form['#attached']['css'][] = drupal_get_path('module', 'node') . '/css/node.module.css';
$form['#attached']['library'][] = 'seven/node-form';
$form['advanced']['#type'] = 'container';
$is_new = !$node->isNew() ? format_date($node->getChangedTime(), 'short') : t('Not saved yet');
......
......@@ -4,8 +4,7 @@ description: 'An intentionally plain theme with almost no styling to demonstrate
package: Core
version: VERSION
core: 8.x
stylesheets:
all:
- css/layout.css
libraries:
- stark/global-styling
stylesheets-remove:
- normalize.css
global-styling:
version: VERSION
css:
base:
css/layout.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