core/lib/Drupal/Core/Extension/ThemeHandler.php | 48 +--------------------- core/lib/Drupal/Core/Theme/ActiveTheme.php | 17 -------- core/lib/Drupal/Core/Theme/ThemeInitialization.php | 19 --------- core/modules/node/node.libraries.yml | 6 +++ core/modules/node/src/NodeForm.php | 2 + core/modules/system/system.module | 11 +---- .../modules/theme_test/src/ThemeTestController.php | 10 +---- .../modules/theme_test/theme_test.libraries.yml | 10 +++++ .../themes/test_basetheme/test_basetheme.info.yml | 7 +--- .../test_basetheme/test_basetheme.libraries.yml | 7 ++++ .../themes/test_subtheme/test_subtheme.info.yml | 5 +-- .../test_subtheme/test_subtheme.libraries.yml | 5 +++ core/modules/toolbar/toolbar.api.php | 4 +- .../Tests/Core/Extension/ThemeHandlerTest.php | 40 +----------------- core/themes/seven/seven.info.yml | 35 +--------------- core/themes/seven/seven.libraries.yml | 47 +++++++++++++++++++++ core/themes/seven/seven.theme | 2 +- core/themes/stark/stark.info.yml | 5 +-- core/themes/stark/stark.libraries.yml | 5 +++ 19 files changed, 99 insertions(+), 186 deletions(-) diff --git a/core/lib/Drupal/Core/Extension/ThemeHandler.php b/core/lib/Drupal/Core/Extension/ThemeHandler.php index 02100fb..8beb184 100644 --- a/core/lib/Drupal/Core/Extension/ThemeHandler.php +++ b/core/lib/Drupal/Core/Extension/ThemeHandler.php @@ -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(); @@ -556,41 +547,6 @@ public function rebuildThemeData() { } /** - * 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} */ public function getBaseThemes(array $themes, $theme) { diff --git a/core/lib/Drupal/Core/Theme/ActiveTheme.php b/core/lib/Drupal/Core/Theme/ActiveTheme.php index b0940dc..dfccdc4 100644 --- a/core/lib/Drupal/Core/Theme/ActiveTheme.php +++ b/core/lib/Drupal/Core/Theme/ActiveTheme.php @@ -60,13 +60,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. * * @var array @@ -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']; @@ -163,15 +155,6 @@ public function getLibraries() { } /** - * Returns the stylesheets provided by the theme. - * - * @return mixed - */ - public function getStyleSheets() { - return $this->styleSheets; - } - - /** * Returns the overridden stylesheets by the theme. * * @return mixed diff --git a/core/lib/Drupal/Core/Theme/ThemeInitialization.php b/core/lib/Drupal/Core/Theme/ThemeInitialization.php index bbe5cc7..0dbd0c6 100644 --- a/core/lib/Drupal/Core/Theme/ThemeInitialization.php +++ b/core/lib/Drupal/Core/Theme/ThemeInitialization.php @@ -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(); diff --git a/core/modules/node/node.libraries.yml b/core/modules/node/node.libraries.yml index 231687e..2b3d80d 100644 --- a/core/modules/node/node.libraries.yml +++ b/core/modules/node/node.libraries.yml @@ -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: diff --git a/core/modules/node/src/NodeForm.php b/core/modules/node/src/NodeForm.php index 7f9ef84..7e0a854 100644 --- a/core/modules/node/src/NodeForm.php +++ b/core/modules/node/src/NodeForm.php @@ -205,6 +205,8 @@ public function form(array $form, FormStateInterface $form_state) { $form['sticky']['#group'] = 'options'; } + $form['#attached']['library'][] = 'node/form'; + return $form; } diff --git a/core/modules/system/system.module b/core/modules/system/system.module index 9334a88..79d20c0 100644 --- a/core/modules/system/system.module +++ b/core/modules/system/system.module @@ -532,20 +532,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')) { diff --git a/core/modules/system/tests/modules/theme_test/src/ThemeTestController.php b/core/modules/system/tests/modules/theme_test/src/ThemeTestController.php index fb8e1f9..cf42211 100644 --- a/core/modules/system/tests/modules/theme_test/src/ThemeTestController.php +++ b/core/modules/system/tests/modules/theme_test/src/ThemeTestController.php @@ -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', ), ), ); diff --git a/core/modules/system/tests/modules/theme_test/theme_test.libraries.yml b/core/modules/system/tests/modules/theme_test/theme_test.libraries.yml new file mode 100644 index 0000000..b08521e --- /dev/null +++ b/core/modules/system/tests/modules/theme_test/theme_test.libraries.yml @@ -0,0 +1,10 @@ +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: {} diff --git a/core/modules/system/tests/themes/test_basetheme/test_basetheme.info.yml b/core/modules/system/tests/themes/test_basetheme/test_basetheme.info.yml index 2edc823..8be3fc9 100644 --- a/core/modules/system/tests/themes/test_basetheme/test_basetheme.info.yml +++ b/core/modules/system/tests/themes/test_basetheme/test_basetheme.info.yml @@ -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/styling stylesheets-override: - base-override.css - base-override.sub-remove.css diff --git a/core/modules/system/tests/themes/test_basetheme/test_basetheme.libraries.yml b/core/modules/system/tests/themes/test_basetheme/test_basetheme.libraries.yml new file mode 100644 index 0000000..e92c9c0 --- /dev/null +++ b/core/modules/system/tests/themes/test_basetheme/test_basetheme.libraries.yml @@ -0,0 +1,7 @@ +styling: + version: VERSION + css: + base: + base-add.css: {} + base-add.sub-override.css: {} + base-add.sub-remove.css: {} diff --git a/core/modules/system/tests/themes/test_subtheme/test_subtheme.info.yml b/core/modules/system/tests/themes/test_subtheme/test_subtheme.info.yml index cdcd8f0..2cc9409 100644 --- a/core/modules/system/tests/themes/test_subtheme/test_subtheme.info.yml +++ b/core/modules/system/tests/themes/test_subtheme/test_subtheme.info.yml @@ -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/styling stylesheets-override: - css/sub-override.css - css/base-add.sub-override.css diff --git a/core/modules/system/tests/themes/test_subtheme/test_subtheme.libraries.yml b/core/modules/system/tests/themes/test_subtheme/test_subtheme.libraries.yml new file mode 100644 index 0000000..865c091 --- /dev/null +++ b/core/modules/system/tests/themes/test_subtheme/test_subtheme.libraries.yml @@ -0,0 +1,5 @@ +styling: + version: VERSION + css: + base: + css/sub-add.css: {} diff --git a/core/modules/toolbar/toolbar.api.php b/core/modules/toolbar/toolbar.api.php index bce69ae..5e9dd39 100644 --- a/core/modules/toolbar/toolbar.api.php +++ b/core/modules/toolbar/toolbar.api.php @@ -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', ), ), ); diff --git a/core/tests/Drupal/Tests/Core/Extension/ThemeHandlerTest.php b/core/tests/Drupal/Tests/Core/Extension/ThemeHandlerTest.php index 5dba9db..512d8c0 100644 --- a/core/tests/Drupal/Tests/Core/Extension/ThemeHandlerTest.php +++ b/core/tests/Drupal/Tests/Core/Extension/ThemeHandlerTest.php @@ -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/styling'), $info->info['libraries']); } /** diff --git a/core/themes/seven/seven.info.yml b/core/themes/seven/seven.info.yml index 1277db9..0bca835 100644 --- a/core/themes/seven/seven.info.yml +++ b/core/themes/seven/seven.info.yml @@ -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/styling stylesheets-override: - css/components/vertical-tabs.css - css/components/jquery.ui.theme.css diff --git a/core/themes/seven/seven.libraries.yml b/core/themes/seven/seven.libraries.yml index a794871..6b53411 100644 --- a/core/themes/seven/seven.libraries.yml +++ b/core/themes/seven/seven.libraries.yml @@ -1,3 +1,49 @@ +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/styling install-page: version: VERSION diff --git a/core/themes/seven/seven.theme b/core/themes/seven/seven.theme index 76ddfcc..d4e58cb 100644 --- a/core/themes/seven/seven.theme +++ b/core/themes/seven/seven.theme @@ -176,7 +176,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'); diff --git a/core/themes/stark/stark.info.yml b/core/themes/stark/stark.info.yml index 6ce7cc6..cc238a8 100644 --- a/core/themes/stark/stark.info.yml +++ b/core/themes/stark/stark.info.yml @@ -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/styling stylesheets-remove: - normalize.css diff --git a/core/themes/stark/stark.libraries.yml b/core/themes/stark/stark.libraries.yml new file mode 100644 index 0000000..56d01cd --- /dev/null +++ b/core/themes/stark/stark.libraries.yml @@ -0,0 +1,5 @@ +styling: + version: VERSION + css: + base: + css/layout.css: {}