Unverified Commit 599d4e09 authored by Alex Pott's avatar Alex Pott
Browse files

Issue #3069052 by mikelutz, Berdir, longwave, ravi.shankar, voleger, lauriii,...

Issue #3069052 by mikelutz, Berdir, longwave, ravi.shankar, voleger, lauriii, catch, andypost: Properly deprecate the stylesheets-remove key from theme info.yml files
parent 9df1ea9b
Loading
Loading
Loading
Loading
+9 −2
Original line number Diff line number Diff line
@@ -209,11 +209,18 @@ public function getLibraries() {
  /**
   * Returns the removed stylesheets by the theme.
   *
   * @return mixed
   * This method is used as a BC layer to access the contents of the deprecated
   * stylesheets-remove key in theme info.yml files. It will be removed once it
   * is no longer needed in Drupal 10.
   *
   * @deprecated in drupal:8.0.0 and is removed from drupal:9.0.0.
   * @return mixed
   *   The removed stylesheets.
   *
   * @see https://www.drupal.org/node/2497313
   *
   * @todo Remove in Drupal 10.0.x.
   *
   * @internal
   */
  public function getStyleSheetsRemove() {
    return $this->styleSheetsRemove;
+10 −2
Original line number Diff line number Diff line
@@ -182,7 +182,7 @@ public function getActiveTheme(Extension $theme, array $base_themes = []) {
      $values['logo'] = $theme->getPath() . '/logo.svg';
    }

    // @todo Remove in Drupal 9.0.x.
    // @todo Remove in Drupal 10.0.x.
    $values['stylesheets_remove'] = $this->prepareStylesheetsRemove($theme, $base_themes);

    // Prepare libraries overrides from this theme and ancestor themes. This
@@ -312,6 +312,10 @@ protected function resolveStyleSheetPlaceholders($css_file) {
  /**
   * Prepares stylesheets-remove specified in the *.info.yml file.
   *
   * This method is used as a BC layer to access the contents of the deprecated
   * stylesheets-remove key in theme info.yml files. It will be removed once it
   * is no longer needed in Drupal 10.
   *
   * @param \Drupal\Core\Extension\Extension $theme
   *   The theme extension object.
   * @param \Drupal\Core\Extension\Extension[] $base_themes
@@ -320,7 +324,9 @@ protected function resolveStyleSheetPlaceholders($css_file) {
   * @return string[]
   *   The list of stylesheets-remove specified in the *.info.yml file.
   *
   * @todo Remove in Drupal 9.0.x.
   * @todo Remove in Drupal 10.0.x.
   *
   * @internal
   */
  protected function prepareStylesheetsRemove(Extension $theme, $base_themes) {
    // Prepare stylesheets from this theme as well as all ancestor themes.
@@ -330,6 +336,7 @@ protected function prepareStylesheetsRemove(Extension $theme, $base_themes) {
    // Grab stylesheets from base theme.
    foreach ($base_themes as $base) {
      if (!empty($base->info['stylesheets-remove'])) {
        @trigger_error('The theme info key stylesheets-remove implemented by theme ' . $base->getName() . ' is deprecated in drupal:8.0.0 and is removed from drupal:10.0.0. See https://www.drupal.org/node/2497313', E_USER_DEPRECATED);
        foreach ($base->info['stylesheets-remove'] as $css_file) {
          $css_file = $this->resolveStyleSheetPlaceholders($css_file);
          $stylesheets_remove[$css_file] = $css_file;
@@ -339,6 +346,7 @@ protected function prepareStylesheetsRemove(Extension $theme, $base_themes) {

    // Add stylesheets used by this theme.
    if (!empty($theme->info['stylesheets-remove'])) {
      @trigger_error('The theme info key stylesheets-remove implemented by theme ' . $theme->getName() . ' is deprecated in drupal:8.0.0 and is removed from drupal:10.0.0. See https://www.drupal.org/node/2497313', E_USER_DEPRECATED);
      foreach ($theme->info['stylesheets-remove'] as $css_file) {
        $css_file = $this->resolveStyleSheetPlaceholders($css_file);
        $stylesheets_remove[$css_file] = $css_file;
+41 −0
Original line number Diff line number Diff line
<?php

namespace Drupal\Tests\system\Functional\Theme;

use Drupal\Tests\BrowserTestBase;

/**
 * Tests the legacy stylesheets-remove key.
 *
 * @group system
 * @group legacy
 */
class LegacyStyleSheetsRemoveTest extends BrowserTestBase {

  /**
   * {@inheritdoc}
   */
  protected function setUp() {
    parent::setUp();
    \Drupal::service('theme_installer')->install(['test_legacy_stylesheets_remove']);
  }

  /**
   * Tests the stylesheets-remove key.
   *
   * @throws \Behat\Mink\Exception\ExpectationException
   *
   * @expectedDeprecation The theme info key stylesheets-remove implemented by theme test_legacy_stylesheets_remove is deprecated in drupal:8.0.0 and is removed from drupal:10.0.0. See https://www.drupal.org/node/2497313
   */
  public function testStyleSheetsRemove() {
    \Drupal::configFactory()->getEditable('system.theme')->set('default', 'classy')->save();
    $this->drupalGet('<front>');
    $this->assertSession()->responseContains('css/components/action-links.css?');
    $this->assertSession()->responseContains('css/components/breadcrumb.css?');
    \Drupal::configFactory()->getEditable('system.theme')->set('default', 'test_legacy_stylesheets_remove')->save();
    $this->drupalGet('<front>');
    $this->assertSession()->responseNotContains('css/components/action-links.css?');
    $this->assertSession()->responseContains('css/components/breadcrumb.css?');
  }

}
+4 −2
Original line number Diff line number Diff line
@@ -8,8 +8,6 @@ hidden: true

libraries:
  - test_basetheme/global-styling
stylesheets-remove:
  - '@theme_test/css/base-remove.css'
libraries-override:
  core/drupal.dialog:
    js:
@@ -18,6 +16,10 @@ libraries-override:
    css:
      component:
        assets/vendor/farbtastic/farbtastic.css: css/farbtastic.css
  theme_test/theme_stylesheets_override_and_remove_test:
    css:
      base:
        css/base-remove.css: false

libraries-extend:
  classy/base:
+9 −0
Original line number Diff line number Diff line
name: 'Theme Legacy Test Stylesheets Remove'
type: theme
description: 'Test theme using legacy stylesheets-remove.'
version: VERSION
core: 8.x
base theme: classy
libraries: { }
stylesheets-remove:
  - '@classy/css/components/action-links.css'
Loading