Unverified Commit b2f34213 authored by Lauri Timmanee's avatar Lauri Timmanee
Browse files

Issue #3269143 by longwave, catch: Remove deprecated theme key stylesheets-remove

parent 367742e4
Loading
Loading
Loading
Loading
+0 −10
Original line number Diff line number Diff line
@@ -162,16 +162,6 @@ public function getCssAssets(AttachedAssetsInterface $assets, $optimize) {
    // Sort CSS items, so that they appear in the correct order.
    uasort($css, 'static::sort');

    // Allow themes to remove CSS files by CSS files full path and file name.
    // @todo Remove in Drupal 9.0.x.
    if ($stylesheet_remove = $theme_info->getStyleSheetsRemove()) {
      foreach ($css as $key => $options) {
        if (isset($stylesheet_remove[$key])) {
          unset($css[$key]);
        }
      }
    }

    if ($optimize) {
      $css = \Drupal::service('asset.css.collection_optimizer')->optimize($css);
    }
+0 −29
Original line number Diff line number Diff line
@@ -62,13 +62,6 @@ class ActiveTheme {
   */
  protected $extension;

  /**
   * The stylesheets which are set to be removed by the theme.
   *
   * @var array
   */
  protected $styleSheetsRemove;

  /**
   * The libraries provided by the theme.
   *
@@ -109,7 +102,6 @@ public function __construct(array $values) {
      'engine' => 'twig',
      'owner' => 'twig',
      'logo' => '',
      'stylesheets_remove' => [],
      'libraries' => [],
      'extension' => 'html.twig',
      'base_theme_extensions' => [],
@@ -123,7 +115,6 @@ public function __construct(array $values) {
    $this->path = $values['path'];
    $this->engine = $values['engine'];
    $this->owner = $values['owner'];
    $this->styleSheetsRemove = $values['stylesheets_remove'];
    $this->libraries = $values['libraries'];
    $this->extension = $values['extension'];
    $this->baseThemeExtensions = $values['base_theme_extensions'];
@@ -188,26 +179,6 @@ public function getLibraries() {
    return $this->libraries;
  }

  /**
   * Returns the removed stylesheets by the theme.
   *
   * 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.
   *
   * @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;
  }

  /**
   * Returns an array of base theme extension objects keyed by name.
   *
+0 −49
Original line number Diff line number Diff line
@@ -179,9 +179,6 @@ public function getActiveTheme(Extension $theme, array $base_themes = []) {
      $values['logo'] = $theme->getPath() . '/logo.svg';
    }

    // @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
    // allows child themes to easily remove CSS files from base themes and
    // modules.
@@ -306,50 +303,4 @@ 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
   *   An array of base themes.
   *
   * @return string[]
   *   The list of stylesheets-remove specified in the *.info.yml file.
   *
   * @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.
    // We work it this way so that we can have child themes remove CSS files
    // easily from parent.
    $stylesheets_remove = [];
    // 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;
        }
      }
    }

    // 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;
      }
    }
    return $stylesheets_remove;
  }

}
+0 −7
Original line number Diff line number Diff line
theme_test.info_stylesheets:
  path: '/theme-test/info/stylesheets'
  defaults:
    _controller: '\Drupal\theme_test\ThemeTestController::testInfoStylesheets'
  requirements:
    _access: 'TRUE'

theme_test.template_test:
  path: '/theme-test/template-test'
  defaults:
+0 −45
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 $defaultTheme = 'stark';

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

  /**
   * Tests the stylesheets-remove key.
   *
   * @throws \Behat\Mink\Exception\ExpectationException
   */
  public function testStyleSheetsRemove() {
    $this->expectDeprecation('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');
    \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?');
  }

}
Loading