Problem/Motivation

See: #2489460: [Meta] Move module.theme.css files to Classy or Seven

Proposed resolution

Move the CSS files to classy
Rename the files to remove the .theme. extension
Alter the system.base library so the CSS files are loaded with a similar weight to before

Remaining tasks

Test steps

Check that the CSS file was deleted from the module and added to Classy
Check that the references to that CSS file removed from the system module
Check that the CSS file is being loaded in the correct places in Classy
Check that there are no HTML classes in the module that relies on the theme CSS

User interface changes

None for Classy, Stark will be more Stark

API changes

None

Comments

mdrummond created an issue. See original summary.

davidhernandez’s picture

See this issue #2505931: Remove SafeMarkup::set in ViewListBuilder

I had to make some CSS changes to item list that should not be moved to Classy. Basically, added some declarations for "comma-list". Those really need to stay in core in a item-list.module.css, but it was hard to do that without refactoring some of the item list CSS, including things in Seven and Bartik. Those would have been out of scopr for the other issue. That should be easier to do with the main item list CSS moved to Classy.

The easiest thing would probably be to move the main item list declarations to Classy, remove the ul specificity, and then refactor what is needed.

If someone works on this, ping me and I'll explain it better. I can also work on this myself, but I wanted to make this comment so I don't forget.

joelpittet’s picture

Some work has been done in #2557367: Fix inline list CSS FYI, @davidhernandez found the connection.

rainbowarray’s picture

Title: Move system item-list.theme.css, tabledrag.theme.css, tableselect.theme.css, and tablesort.theme.css to Classy » Move system tabledrag.theme.css, tableselect.theme.css, and tablesort.theme.css to Classy

Taking item-list out of this group since #2557367: Fix inline list CSS is handling that by moving those rules to item-list.module.css.

rainbowarray’s picture

Status: Active » Needs review
StatusFileSize
new2.01 KB

Keeping the CSS in base/theme so things load in the same order.

emma.maria’s picture

I carried out the test steps and can confirm the following:

✔︎ Check that the CSS file was deleted from the module and added to Classy
– tabledrag.theme.css no longer exists in the module and tabledrag.css now exists in Classy.
– tableselect.theme.css no longer exists in the module and tableselect.css now exists in Classy.
– tablesort.theme.css no longer exists in the module and tablesort.css now exists in Classy.

✔︎ Check that the references to that CSS file removed from the system module
– References to tabledrag.theme.css, tableselect.theme.css and tablesort.theme.css within system.libraries.yml have been removed.

✔︎ Check that the CSS file is being loaded in the correct places in Classy
– tabledrag.css, tableselect.css and tablesort.css are being loaded within Classy in the same order as the originals in system.libraries.yml

✔︎ Check that there are no HTML classes in the module that relies on the theme CSS
- I couldn't find any markup references to CSS in tabledrag.css, tableselect.css or tablesort.css.

lauriii’s picture

Status: Needs review » Reviewed & tested by the community
davidhernandez’s picture

+++ b/core/themes/classy/classy.libraries.yml
@@ -2,6 +2,9 @@ base:
     theme:
+      css/components/tableselect.css: { weight: -10 }
+      css/components/tabledrag.css: { weight: -10 }
+      css/components/tablesort.css: { weight: -10 }

Agreed, these should be globally included. Posting the same question I've been posted elsewhere, should these be in a 'theme' folder since they are being added in the theme category? Otherwise, looks good.

rainbowarray’s picture

Status: Reviewed & tested by the community » Needs review
StatusFileSize
new2.01 KB
new517 bytes

We should keep these consistent. Moving CSS to the component section. This helps to maintain the same CSS file load order.

davidhernandez’s picture

Issue summary: View changes
StatusFileSize
new416.3 KB
new309.59 KB

This is what I'm seeing. Changing the category changes the ordering more significantly, putting the files lower in the cascade. I think leaving it in theme is fine. I was suggesting putting the files into a theme folder to keep it consistent with the categories. Does that make sense?

I'm actually looking at Bartik and Seven and they both seem a bit inconsistent with this regard.

before

after

rainbowarray’s picture

Blergh. I just updated all the CSS moving issues to put the theme CSS files in the component group instead of the theme group because supposedly that was going to keep the order more consistent, even though by definition the files better belong in the theme group.

If placing the CSS files in the component group still means the load order will be significantly different with these changes, I don't see the point to putting them in the component group.

I don't think we're going to be able to get the same load order no matter what we do, to be honest. My memory is that module CSS files are loaded in first, then theme CSS files, in order to give themes an opportunity to override module CSS files. If that's still the case in D8, then we should just use the library group that makes sense (theme) and check for visual discrepancies.

But no matter what, we will already need to do a follow-up to clean up inconsistencies. There are already files in Classy that end in .theme.css. You also brought up the fact that we are calling this the components folder (which is consistent with core, Seven and Bartik) versus the library key of component.

Personally, if this was my theme, I'd definitely put these in a components folder, not a theme folder. They are styles for individual components on the site. In SMACSS, the theme group should be reserved for something that should be easily skinnable, like the color of a button or maybe a font. We definitely have styles in these CSS files that are more than just that.

So... I don't know. Maybe these do belong in the component library group and the components folder.

Also, I think the components folder is fine for the name. Each file in there is a component. Having a plural on the folder name makes sense. It's the component group, a group of components. I'm not bothered by the difference.

davidhernandez’s picture

I'm not sure where the suggestion of putting them in the component group came from. I think we were ok. (Well I added some stuff in component to get it higher.) I was just suggesting changing the directory where the files are stored, since we are adding things using the theme group. Since most of these are coming from the theme group, added by system, moving to component is a bigger change.

I don't think there is anything we can do to keep the ordering exactly the same. As you've noted, the module css gets added higher. I think best we can do is get it high in the category, since it is a base theme. What I've been doing is checking the ordering to make sure it at least is before any similar css being added by Bartik or Seven.

...actually, I partial recant. Why are they dropping in order. Moving from theme to component should put them higher. Can someone else test?

joelpittet’s picture

I agree with @mdrummond's assessment in #11. And SMACSS theme should be able to override a component. So putting something in theme should be higher than component IMO.

Search Component:
.search { border: 1px solid silver; }

Search Seven Theme:
.search { background-color: tan; }

https://smacss.com/book/type-theme#themes

Don't mean to step on your toes here, I'm sure you both know more more what's going on in banana land than I do.

rainbowarray’s picture

Theme should in fact be lower than component styles, precisely so that it can override. Rules in CSS files that are loaded later can override the same rules in CSS files loaded earlier.

So really the only concern we have in terms of order is if previously, a rule in a CSS file that was loaded later was overwriting a rule in a CSS file that was loaded earlier. If that's not happening, then the order is not make or break.

Because theme CSS will always load later than module CSS, I think we're actually better off putting CSS files that were in the theme group in core also in the theme group in Classy. At least that will help to maintain the load order within the theme. If any component group CSS files get moved to Classy (and probably not?), then the theme files would still come afterwards in the cascade, letting theme file rules trump component file rules, as before.

Here's the docs page on the CSS file organization, which goes into the load order: https://www.drupal.org/node/1887922

One thing I'm seeing is that conditionally-loaded libraries will always come after libraries loaded on every page. I'd bet a nickel that's what's causing some of the discrepancies.

Based on the examples, I'd also say that these really are component styles, not theme styles. Yes, they're in a theme, but they're not strictly the sort of aesthetic styles that would fall into the SMACSS theme category. Maybe I just haven't looked close enough, but I think that's the case.

davidhernandez’s picture

Right, theme should be lower than component, to override it. That is why I was confused why switching from theme to component made it drop so much lower in the order.

I wasn't working on core when most of the ordering was designed, and hadn't delved into, so I keep making assumptions. That'll get me in trouble.

So I assumed the ordering would work like this:

base
- modules
- base theme
- child theme

component
- modules
- base theme
- child theme

theme
- modules
- base theme
- child theme
...

but it looks like it does this:

modules
- base
- component
- theme

themes all together
- base
- component
- theme
...

Is that right? If so that is less flexible than I thought, but whatever. We won't be able to control the ordering to match the original then. We just need to make sure the files are getting included higher in the order to come before child theme CSS. That is my main worry. So putting them all in component with weights might be the best thing.

What we're really deciding is whether all Classy CSS should come before the child theme CSS. If yes, then there is no point putting any of it in theme.

lewisnyman’s picture

By the SMACSS definition, theme should be used very very rarely. The problem we have here is that we have a bit of a mixed meaning in Drupal, because we originally associated 'theme' to be a Drupal theme as part of the the MAT definition (Module/Admin/Theme). These groupings were originally created to make it easy for themers to remove all non-essential module CSS in their theme.

Moving all the *.theme.css files to Classy removes the need to distinguish these two groups, the Classy and Stark separation achieves this for us.

rainbowarray’s picture

Okay, so based on the discussion, I think this patch is using the correct grouping? Could somebody do a visual check, and if all looks well, wave the RTBC wand?

lewisnyman’s picture

Status: Needs review » Needs work
Issue tags: +Needs reroll

Yes this looks correct. It needs a reroll though.

jaxxed’s picture

re-rolled #9 based on 8.0.x

jaxxed’s picture

Assigned: Unassigned » jaxxed
Status: Needs work » Needs review
lewisnyman’s picture

Assigned: jaxxed » Unassigned
Status: Needs review » Reviewed & tested by the community
Issue tags: -Needs reroll

Great, thanks

lewisnyman’s picture

Status: Reviewed & tested by the community » Postponed
davidhernandez’s picture

Status: Postponed » Closed (fixed)

The mega was committed so we don't need this.