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() { ...@@ -396,12 +396,6 @@ public function listInfo() {
* {@inheritdoc} * {@inheritdoc}
*/ */
public function addTheme(Extension $theme) { 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) { foreach ($theme->info['libraries'] as $library => $name) {
$theme->libraries[$library] = $name; $theme->libraries[$library] = $name;
} }
...@@ -471,7 +465,6 @@ public function rebuildThemeData() { ...@@ -471,7 +465,6 @@ public function rebuildThemeData() {
'features' => $this->defaultFeatures, 'features' => $this->defaultFeatures,
'screenshot' => 'screenshot.png', 'screenshot' => 'screenshot.png',
'php' => DRUPAL_MINIMUM_PHP, 'php' => DRUPAL_MINIMUM_PHP,
'stylesheets' => array(),
'libraries' => array(), 'libraries' => array(),
); );
...@@ -507,11 +500,9 @@ public function rebuildThemeData() { ...@@ -507,11 +500,9 @@ public function rebuildThemeData() {
$theme->prefix = $engines[$engine]->getName(); $theme->prefix = $engines[$engine]->getName();
} }
// Prefix stylesheets and screenshot with theme path. // Prefix screenshot with theme path.
$path = $theme->getPath();
$theme->info['stylesheets'] = $this->themeInfoPrefixPath($theme->info['stylesheets'], $path);
if (!empty($theme->info['screenshot'])) { if (!empty($theme->info['screenshot'])) {
$theme->info['screenshot'] = $path . '/' . $theme->info['screenshot']; $theme->info['screenshot'] = $theme->getPath() . '/' . $theme->info['screenshot'];
} }
$files[$key] = $theme->getPathname(); $files[$key] = $theme->getPathname();
...@@ -555,41 +546,6 @@ public function rebuildThemeData() { ...@@ -555,41 +546,6 @@ public function rebuildThemeData() {
return $themes; 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} * {@inheritdoc}
*/ */
......
...@@ -59,13 +59,6 @@ class ActiveTheme { ...@@ -59,13 +59,6 @@ class ActiveTheme {
*/ */
protected $extension; protected $extension;
/**
* The provided stylesheet of the theme.
*
* @var array
*/
protected $styleSheets;
/** /**
* The stylesheets which are set to be removed by the theme. * The stylesheets which are set to be removed by the theme.
* *
...@@ -98,7 +91,6 @@ public function __construct(array $values) { ...@@ -98,7 +91,6 @@ public function __construct(array $values) {
$this->path = $values['path']; $this->path = $values['path'];
$this->engine = $values['engine']; $this->engine = $values['engine'];
$this->owner = $values['owner']; $this->owner = $values['owner'];
$this->styleSheets = $values['stylesheets'];
$this->styleSheetsRemove = $values['stylesheets_remove']; $this->styleSheetsRemove = $values['stylesheets_remove'];
$this->styleSheetsOverride = $values['stylesheets_override']; $this->styleSheetsOverride = $values['stylesheets_override'];
$this->libraries = $values['libraries']; $this->libraries = $values['libraries'];
...@@ -162,15 +154,6 @@ public function getLibraries() { ...@@ -162,15 +154,6 @@ public function getLibraries() {
return $this->libraries; 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. * Returns the overridden stylesheets by the theme.
* *
......
...@@ -154,22 +154,13 @@ public function getActiveTheme(Extension $theme, array $base_themes = []) { ...@@ -154,22 +154,13 @@ public function getActiveTheme(Extension $theme, array $base_themes = []) {
// Prepare stylesheets from this theme as well as all ancestor 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 // We work it this way so that we can have child themes override parent
// theme stylesheets easily. // theme stylesheets easily.
$values['stylesheets'] = array();
// CSS file basenames to override, pointing to the final, overridden filepath. // CSS file basenames to override, pointing to the final, overridden filepath.
$values['stylesheets_override'] = array(); $values['stylesheets_override'] = array();
// CSS file basenames to remove. // CSS file basenames to remove.
$values['stylesheets_remove'] = array(); $values['stylesheets_remove'] = array();
// Grab stylesheets from base theme. // Grab stylesheets from base theme.
$final_stylesheets = array();
foreach ($base_themes as $base) { 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(); $base_theme_path = $base->getPath();
if (!empty($base->info['stylesheets-remove'])) { if (!empty($base->info['stylesheets-remove'])) {
foreach ($base->info['stylesheets-remove'] as $basename) { foreach ($base->info['stylesheets-remove'] as $basename) {
...@@ -185,13 +176,6 @@ public function getActiveTheme(Extension $theme, array $base_themes = []) { ...@@ -185,13 +176,6 @@ public function getActiveTheme(Extension $theme, array $base_themes = []) {
} }
// Add stylesheets used by this theme. // 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'])) { if (!empty($theme->info['stylesheets-remove'])) {
foreach ($theme->info['stylesheets-remove'] as $basename) { foreach ($theme->info['stylesheets-remove'] as $basename) {
$values['stylesheets_remove'][$basename] = $theme_path . '/' . $basename; $values['stylesheets_remove'][$basename] = $theme_path . '/' . $basename;
...@@ -212,9 +196,6 @@ public function getActiveTheme(Extension $theme, array $base_themes = []) { ...@@ -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 // Do basically the same as the above for libraries
$values['libraries'] = array(); $values['libraries'] = array();
......
...@@ -30,6 +30,12 @@ drupal.content_types: ...@@ -30,6 +30,12 @@ drupal.content_types:
- core/drupal - core/drupal
- core/drupal.form - core/drupal.form
form:
version: VERSION
css:
layout:
css/node.module.css: {}
drupal.node.admin: drupal.node.admin:
version: VERSION version: VERSION
css: css:
......
...@@ -205,6 +205,8 @@ public function form(array $form, FormStateInterface $form_state) { ...@@ -205,6 +205,8 @@ public function form(array $form, FormStateInterface $form_state) {
$form['sticky']['#group'] = 'options'; $form['sticky']['#group'] = 'options';
} }
$form['#attached']['library'][] = 'node/form';
return $form; return $form;
} }
......
...@@ -528,20 +528,11 @@ function system_page_attachments(array &$page) { ...@@ -528,20 +528,11 @@ function system_page_attachments(array &$page) {
$page['#attached']['library'][] = 'system/admin'; $page['#attached']['library'][] = 'system/admin';
} }
// Attach libraries and CSS used by this theme. // Attach libraries used by this theme.
$active_theme = \Drupal::theme()->getActiveTheme(); $active_theme = \Drupal::theme()->getActiveTheme();
foreach ($active_theme->getLibraries() as $library) { foreach ($active_theme->getLibraries() as $library) {
$page['#attached']['library'][] = $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. // Attach favicon.
if (theme_get_setting('features.favicon')) { if (theme_get_setting('features.favicon')) {
......
...@@ -34,16 +34,10 @@ public function functionTemplateOverridden() { ...@@ -34,16 +34,10 @@ public function functionTemplateOverridden() {
* A render array containing custom stylesheets. * A render array containing custom stylesheets.
*/ */
public function testInfoStylesheets() { public function testInfoStylesheets() {
$path = drupal_get_path('module', 'theme_test');
return array( return array(
'#attached' => array( '#attached' => array(
'css' => array( 'library' => array(
"$path/css/base-override.css", 'theme_test/theme_stylesheets_override_and_remove_test',
"$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",
), ),
), ),
); );
......
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 ...@@ -3,11 +3,8 @@ type: theme
description: 'Test theme which acts as a base theme for other test subthemes.' description: 'Test theme which acts as a base theme for other test subthemes.'
version: VERSION version: VERSION
core: 8.x core: 8.x
stylesheets: libraries:
all: - test_basetheme/global-styling
- base-add.css
- base-add.sub-override.css
- base-add.sub-remove.css
stylesheets-override: stylesheets-override:
- base-override.css - base-override.css
- base-override.sub-remove.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.' ...@@ -4,9 +4,8 @@ description: 'Test theme which uses test_basetheme as the base theme.'
version: VERSION version: VERSION
core: 8.x core: 8.x
base theme: test_basetheme base theme: test_basetheme
stylesheets: libraries:
all: - test_subtheme/global-styling
- css/sub-add.css
stylesheets-override: stylesheets-override:
- css/sub-override.css - css/sub-override.css
- css/base-add.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() { ...@@ -60,8 +60,8 @@ function hook_toolbar() {
'#weight' => 200, '#weight' => 200,
// Custom CSS, JS or a library can be associated with the toolbar item. // Custom CSS, JS or a library can be associated with the toolbar item.
'#attached' => array( '#attached' => array(
'css' => array( 'library' => array(
drupal_get_path('module', 'search') . '/css/search.base.css', 'search/global',
), ),
), ),
); );
......
...@@ -170,45 +170,7 @@ public function testRebuildThemeData() { ...@@ -170,45 +170,7 @@ public function testRebuildThemeData() {
$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['libraries']); $this->assertEquals(array('seven/global-styling'), $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']);
} }
/** /**
......
...@@ -6,7 +6,7 @@ package: Core ...@@ -6,7 +6,7 @@ package: Core
version: VERSION version: VERSION
core: 8.x core: 8.x
libraries: libraries:
- bartik/base - bartik/global-styling
ckeditor_stylesheets: ckeditor_stylesheets:
- css/ckeditor-iframe.css - css/ckeditor-iframe.css
regions: regions:
......
base: global-styling:
version: VERSION version: VERSION
css: css:
theme: theme:
...@@ -14,4 +14,4 @@ maintenance_page: ...@@ -14,4 +14,4 @@ maintenance_page:
css/maintenance-page.css: {} css/maintenance-page.css: {}
dependencies: dependencies:
- system/maintenance - system/maintenance
- bartik/base - bartik/global-styling
...@@ -7,39 +7,8 @@ tags: 'multi-column, fluid, responsive, sans-serif, accessible' ...@@ -7,39 +7,8 @@ tags: 'multi-column, fluid, responsive, sans-serif, accessible'
package: Core package: Core
version: VERSION version: VERSION
core: 8.x core: 8.x
stylesheets: libraries:
screen: - seven/global-styling
- 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
stylesheets-override: stylesheets-override:
- css/components/vertical-tabs.css - css/components/vertical-tabs.css
- css/components/jquery.ui.theme.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: maintenance-page:
version: VERSION version: VERSION
js: js:
...@@ -7,6 +53,7 @@ maintenance-page: ...@@ -7,6 +53,7 @@ maintenance-page:
css/theme/maintenance-page.css: {} css/theme/maintenance-page.css: {}
dependencies: dependencies:
- system/maintenance - system/maintenance
- seven/global-styling
install-page: install-page:
version: VERSION version: VERSION
......
...@@ -167,7 +167,7 @@ function seven_form_node_form_alter(&$form, FormStateInterface $form_state) { ...@@ -167,7 +167,7 @@ function seven_form_node_form_alter(&$form, FormStateInterface $form_state) {
$node = $form_state->getFormObject()->getEntity(); $node = $form_state->getFormObject()->getEntity();
$form['#theme'] = array('node_edit_form'); $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'; $form['advanced']['#type'] = 'container';
$is_new = !$node->isNew() ? format_date($node->getChangedTime(), 'short') : t('Not saved yet'); $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 ...@@ -4,8 +4,7 @@ description: 'An intentionally plain theme with almost no styling to demonstrate
package: Core package: Core
version: VERSION version: VERSION
core: 8.x core: 8.x
stylesheets: libraries:
all: - stark/global-styling
- css/layout.css
stylesheets-remove: stylesheets-remove:
- normalize.css - 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