As originally proposed in #901062: Regression: Themes can no longer remove stylesheets by overriding them in .info files

The actual logic for removing files, especially in combination with base themes as well as potentially also existing stylesheets-override definitions needs careful review and considerations. Also, we need tests.

However, attached patch should hopefully work for a simple test.

Comments

jacine’s picture

Awesome! Not only does this work, but it also fixes this problem: #967166: Content rendered via AJAX does not respect stylesheets removed in .info files.

Here are all the possible combinations (that I can think of) which we need to test:

Description Base theme Sub theme File used
Override combinations:
Theme overrides a stylesheet. stylesheets-override[] = file.css N/A base-theme/file.css
Base theme overrides a stylesheet, sub theme inherits it. stylesheets-override[] = file.css base-theme/file.css
Sub theme overrides a stylesheet. stylesheets-override[] = file.css sub-theme/file.css
Base theme adds a stylesheet, sub theme overrides it. stylesheets[all] = file.css stylesheets-override[] = file.css sub-theme/file.css
Base theme removes a stylesheet, sub theme overrides it. stylesheets-remove[] = file.css stylesheets-override[] = file.css sub-theme/file.css
Remove combinations:
Theme removes a stylesheet. stylesheets-remove[] = file.css N/A None
Base theme removes a stylesheet; sub theme inherits it. stylesheets-remove[] = file.css None
Sub theme removes a stylesheet. stylesheets-remove[] = file.css None
Base theme adds a stylesheet; sub theme removes it. stylesheets[all] = file.css stylesheets-remove[] = file.css None
Base theme overrides a stylesheet, sub theme removes it. stylesheets-override[] = file.css stylesheets-remove[] = file.css None
sun’s picture

Thank you! Very helpful.

AFAICS, this maps into:

- use the last override definition, unless a theme later in the stack removes it.

- remove a file, unless a theme later in the stack overrides it.

sun’s picture

StatusFileSize
new3.18 KB

Incomplete, just to post an update.

sun’s picture

I successfully implemented stylesheets-remove, including full test coverage for the expectations you outlined in #1 in:

#575298: Provide non-PHP way to reliably override CSS

sun’s picture

Status: Needs review » Closed (won't fix)

I don't think I'll have time to (re-)implement this for D7 Edge.

However, the final patch for Drupal 8 core in #575298: Provide non-PHP way to reliably override CSS contains the full-blown stylesheets-remove[] functionality, since it was necessary to complement stylesheets-override[] with that in order to actually make sense of it.

The core patch also contains full test coverage for the add/override/remove plan that @Jacine outlined in #1, for which I'm still very very thankful :)

[Usually one has to make up all kinds of expectations for tests — But writing tests for sophisticated expectations is actually fun! :)]

If anyone badly needs this and wants to backport the D8 code to D7, please feel free to re-open this issue.