Problem/Motivation

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

Proposed resolution

Move the CSS file to classy.
Create a library for the CSS file.
Add the library in the Classy twig template.

Remaining tasks

  1. Figure out what we're allowed to move (see comments).
  2. Move all the things.

User interface changes

None for Classy. Stark will be more stark.

API changes

None

CommentFileSizeAuthor
#68 VOLTRON_1.jpg236.85 KBstar-szr
#66 move_user_theme_css_to-2489564-66-after.png93.45 KBstar-szr
#66 move_user_theme_css_to-2489564-66-before.png94.54 KBstar-szr
#66 move_user_theme_css_to-2489564-66-diff.png399.73 KBstar-szr
#65 move_user_theme_css_to-2489564-65.patch2.17 KBgints.erglis
#63 move_user_theme_css_to-2489564-63.patch2.16 KBLewisNyman
#63 interdiff.txt628 bytesLewisNyman
#60 interdiff-2489564-50-60.txt397 bytesRainbowArray
#60 2489564-60-move-user-css-classy.patch2.16 KBRainbowArray
#50 interdiff.txt582 bytesstar-szr
#50 move_user_theme_css_to-2489564-50.patch2.14 KBstar-szr
#47 2489564-47-comparison.png474.76 KBstar-szr
#47 interdiff.txt759 bytesstar-szr
#47 move_user_theme_css_to-2489564-47.patch2.14 KBstar-szr
#46 move_user_theme_css_to-2489564-46.patch1.87 KBstar-szr
#31 classy-user-loading-order.png110.47 KBsqndr
#23 move_user_theme_css_to-2489564-21-after.png13.49 KBstar-szr
#23 move_user_theme_css_to-2489564-21-before.png13.66 KBstar-szr
#21 move_user_theme_css_to-2489564-21.patch1.84 KBmortendk
#20 move_user_theme_css_to-2489564-20.patch2.2 KBmortendk
#18 user_css_to_classy-2489564-18.patch4.02 KBjstoller
#16 interdiff.txt1.27 KBjstoller
#16 user_css_to_classy-2489564-16.patch4.01 KBjstoller
#13 admin___D8_twig.png210.79 KBmortendk
#13 admin___D8_twig.png393.68 KBmortendk
#13 admin___D8_twig.png412.99 KBmortendk
#12 user_css_to_classy-2489564-11.patch3.29 KBmortendk
#5 user_css_to_classy-2489564-5.patch6.15 KBjstoller
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

jstoller’s picture

Assigned: jstoller » Unassigned
Issue summary: View changes
Issue tags: +Classy

This module brings up a number of issues that need to be addressed before any CSS can be moved. The module contains two *theme.css files: user.icons.theme.css and user.theme.css. The former contains references to background images for the user icon in the toolbar. The later contains styling for the user password editing form. Neither of these correlate to templates in Classy, so while they're undeniably front-end styling there is some question as to what we should do with them.

Based on discussions at DrupalCon, it sounds like the anything dealing with the toolbar should be classified as "admin" and therefore not moved to Classy. If this is the case then perhaps we need to rename user.icons.theme.css to user.icons.admin.css?

The user.theme.css file is a bit more complicated. The markup being targeted by this CSS appears to be coming from user.js, rather than from a template file. Plus, there is already a user.admin.css file and the user.module.css file contains basic styling so the password strength indicator will work. The user.theme.css file just improves that with nicer styling. So, we're a little stuck on how to proceed. Do we need to modify things so the password form has a template file? Can we move user.theme.css to Classy without that template? Can we move user.theme.css to Classy at all, or are we deeming it "admin" and thus unmovable? If it is "admin," then should the CSS be merged into user.admin.css and/or user.module.css, or do we now want to maintain the M.A.T. (module/admin/theme) concept, so we can keep display styling separate from functional styling in cases like this?

LewisNyman’s picture

If this is the case then perhaps we need to rename user.icons.theme.css to user.icons.admin.css?

Yes

The user.theme.css file is a bit more complicated. The markup being targeted by this CSS appears to be coming from user.js, rather than from a template file. Plus, there is already a user.admin.css file and the user.module.css file contains basic styling so the password strength indicator will work.

I think if the styling is clearly theme styling, like the colours for the password indicator, then we should move it to Classy. We can create a followup issue to decide what to do about classes added in Javascript, in this situation it feels like the module is just completing the UI component by adding state classes. I think it's not that bad to have them added in the module but not styled in the module for the time being.

jstoller’s picture

Currently user.theme.css is part of a larger library that's called in user_form_process_password_confirm(), which is the form element process handler for client-side password validation. There's no template to attach it to, so if we remove user.theme.css from the drupal.user library then how do we load the file?

It seems like the cleanest way would be to implement #2451411: Add libraries-override to themes' *.info.yml. Then Classy could just add another CSS file to the existing library provided by the User module. There is the hook_library_info_alter() function, but I'm not sure if it would work for this and it certainly seems really hackie.

Thoughts?

lauriii’s picture

@jstoller: I'm not sure if there is going to be working solution for that other issue anytime soon. As far as I've seen It's quite complicated and there is no work done yet to make it happen. Seven has similar PHP code in seven.theme file so I think it could be copied and used for this purpose. Not optimal but probably necessary at this point.

jstoller’s picture

Here's a first stab at this, applying the approach used in Seven to add a theme CSS file to an existing core library, but it doesn't seem to be working. The CSS is not loading. Anyone have any idea why?

star-szr’s picture

Status: Active » Needs review

@jstoller thanks for all this. It seems to me like the code is working as expected. I'm fairly sure you need to clear caches because the library definitions are cached.

jstoller’s picture

Hmmm. It could be some other issue with my dev environment, but I know I cleared the cache several times from the performance page. If I went to the add user page, the password strength meter was long and grey after my changes, when it should be shorter and colored.

lauriii’s picture

Seems to work for me too!

@jstoller: could you check that your git configuration aligns with the standards that are given here: https://www.drupal.org/documentation/git/configure

jstoller’s picture

@lauriii, do you see a problem with my patch file, or do you think my git config could be somehow causing the code not to work on my system?

lauriii’s picture

The problem is on the patch. With the git config that we suggest to use the patch will became a little bit easier to read :)

mortendk’s picture

reroll

mortendk’s picture

lets try this time with a file

mortendk’s picture

Issue summary: View changes
FileSize
412.99 KB
393.68 KB
210.79 KB

screenshots:
seven:

classy:

Bartik:

sqndr’s picture

+++ b/core/themes/classy/classy.libraries.yml
@@ -3,3 +3,9 @@ base:
+classy.user:

I created a comment to discuss the naming convention for the libraries. I don't feel like we should add the classy. before user, since you're now including classy/classy.user which seems pointless to me. I suggest user.theme, but let's discuss that in the comment.

jstoller’s picture

@sqndr: See my comment on the other issue. While we include "classy/" when adding the dependency, it does not seem that drupal includes that in the way it lists its libraries. If library names must be unique, as it appears they must, then we should namespace them with the theme name.

jstoller’s picture

Seems I was wrong and we don't need to worry about name conflicts in hook_library_info_alter(), as long as we add in the missing $module parameter. Apparently Seven is doing this incorrectly as well. The attached patch fixes the hook implementation and removes the unnecessary prefix from the library name.

star-szr’s picture

Status: Needs review » Needs work

Please use $extension, I created #2490936: hook_library_info_alter() docs and function signature are slightly out of date to fix the docs :)

Other than that, looks good!

jstoller’s picture

Status: Needs work » Needs review
FileSize
4.02 KB

Last time I trust that Drupal documentation. ;-)

Here's an updated patch with $module changed to $extension.

star-szr’s picture

Status: Needs review » Needs work

I missed this before, but the patch no longer deletes the user.theme.css from user module ;) #mortendkblaming

mortendk’s picture

Status: Needs work » Needs review
FileSize
2.2 KB

assign blame !
rerolled the patch

mortendk’s picture

lets try this again and also rename icons.theme

mortendk’s picture

As a follow up as its out of scope (so DONT add it to this patch)
We should look at what to do with the user.admin.css its all css that should live over in seven #2491149: move user.admin.css into seven where it belongs

star-szr’s picture

There's something going on where visually it looks slightly different in Seven (less spacing underneath the Password strength), I did notice that the Classy CSS is being loaded at the very end which seems wrong.

Does this have anything to do with #2474091: CSS files from themes are being loaded in reversed order or are we just using it wrong somehow?

Before:

With #21:

<style media="all">
@import url("http://d8.dev/core/themes/seven/css/base/elements.css?0");
@import url("http://d8.dev/core/themes/seven/css/base/typography.css?0");
@import url("http://d8.dev/core/themes/seven/css/base/print.css?0");
@import url("http://d8.dev/core/themes/seven/css/layout/layout.css?0");
@import url("http://d8.dev/core/themes/seven/css/components/jquery.ui/theme.css?0");
@import url("http://d8.dev/core/themes/seven/css/components/admin-list.css?0");
@import url("http://d8.dev/core/themes/seven/css/components/content-header.css?0");
@import url("http://d8.dev/core/themes/seven/css/components/breadcrumb.css?0");
@import url("http://d8.dev/core/themes/seven/css/components/buttons.css?0");
@import url("http://d8.dev/core/themes/seven/css/components/colors.css?0");
@import url("http://d8.dev/core/themes/seven/css/components/messages.css?0");
@import url("http://d8.dev/core/themes/seven/css/components/dropbutton.component.css?0");
@import url("http://d8.dev/core/themes/seven/css/components/entity-meta.css?0");
@import url("http://d8.dev/core/themes/seven/css/components/field-ui.css?0");
@import url("http://d8.dev/core/themes/seven/css/components/form.css?0");
@import url("http://d8.dev/core/themes/seven/css/components/help.css?0");
@import url("http://d8.dev/core/themes/seven/css/components/menus-and-lists.css?0");
@import url("http://d8.dev/core/themes/seven/css/components/modules-page.css?0");
@import url("http://d8.dev/core/themes/seven/css/components/node.css?0");
@import url("http://d8.dev/core/themes/seven/css/components/page-title.css?0");
@import url("http://d8.dev/core/themes/seven/css/components/pager.css?0");
@import url("http://d8.dev/core/themes/seven/css/components/panel.css?0");
@import url("http://d8.dev/core/themes/seven/css/components/skip-link.css?0");
@import url("http://d8.dev/core/themes/seven/css/components/tables.css?0");
@import url("http://d8.dev/core/themes/seven/css/components/system-status-report.css?0");
@import url("http://d8.dev/core/themes/seven/css/components/tabs.css?0");
@import url("http://d8.dev/core/themes/seven/css/components/tour.theme.css?0");
@import url("http://d8.dev/core/themes/seven/css/components/views-ui.css?0");
@import url("http://d8.dev/core/themes/classy/css/user/user.theme.css?0");
</style>
mortendk’s picture

Theres defently something going on with the cascade - THIS IS WHAT HAPPENS WHEN YOU WRITE SHITTY CSS PEOPLE
... ok time to debug ;)

star-szr’s picture

Even moving the user.theme.css added to Classy in this patch to the 'component' group which is used in most of Seven puts it below all the Seven stuff. Why is that?

star-szr’s picture

And I don't want to derail this issue too much but shouldn't making a library containing a CSS file from core depend on a library containing a CSS file from Classy make the Classy CSS come first? Certainly I would expect/hope JS dependencies to work that way anyway…

mortendk’s picture

I have no idea classy should be loaded first right
order:

  1. Modules
  2. basethme (classy )
  3. theme (seven)
star-szr’s picture

I would think so. Going to try and find some time tonight to poke around at the libraries stuff and see how it's designed.

sqndr’s picture

sqndr’s picture

I have no idea classy should be loaded first right

CSS Loading order

Kitten is a sub theme that has base theme: classy.

The loading order will be

Base styles from Classy, then from Seven/Bartik/Kitten. (Weight: -200)
Layout from Classy, then from Seven/Bartik/Kitten. (Weight: -100)
Component from Classy, then from Seven/Bartik/Kitten. (Weight: 0)
State from Classy, then from Seven/Bartik/Kitten. (Weight: 100)
Theme from Classy, then from Seven/Bartik/Kitten. (Weight: 200)


Needs documentation?

I don't know where the documentation for this is. If there is none, I'll improve the example above and add it to the docs.

sqndr’s picture

Issue summary: View changes
FileSize
110.47 KB

classy.libraries.yml

base:
  version: VERSION
  css:
    component:
      css/user/user.theme.css: {}
    theme:
      css/layout.css: {}

Classy order.


Like this it works. Maybe it's because it's done in an alter hook? Good luck digging into the code Cottser!

jstoller’s picture

I think part of the problem here is that module CSS wasn't built with SMACSS in mind. It was divided by module/admin/theme. Now that we're moving that "theme" CSS over, we'll need to split it up according to SMACCS if we want to be able to load it correctly. Most of the CSS in Seven and Bartik is loaded as components, so we can't just throw everything in "theme" if we want it to load before the sub-themes.

star-szr’s picture

Status: Needs review » Needs work

This may have something to do with Seven's global-styling library being loaded on every page, therefore it comes first. Any library that isn't loaded on every page seems to come after, possibly because of Drupal\Core\Asset\AssetResolver::sort() - see the inline comments there:

// Within a group, order all infrequently needed, page-specific files after
// common files needed throughout the website. Separating this way allows
// for the aggregate file generated for all of the common files to be reused
// across a site visit without being cut by a page using a less common file.

So this kinda works as expected:

user:
  version: VERSION
  css:
    component:
      css/user/user.theme.css: { every_page: true }

But I don't think we want to do that…

It sure would be nice to avoid having to refactor all this CSS as we move it!

jstoller’s picture

It seems to me that we should let Classy do whatever makes sense for Classy and let Seven react to that in a follow-up issue. It's the sub-theme's job to adjust to the base theme, not the other way around.

star-szr’s picture

We can't make D8 less shippable.

jstoller’s picture

I think this depends on your definition of shippable. I'd take CSS in Classy over a small spacing issue in Seven. :-)

Does this mean we need to move away from our current approach and do a larger patch refactoring CSS for all the themes? Do we just add a complementary CSS file to Seven to patch the spacing issue for now?

star-szr’s picture

I didn't mean that this particular issue would do that, but that likely others will have larger repercussions.

mortendk’s picture

isnt the issue here basically that we then have to correct the css in seven so we dont have visual regression ?
then we can move forward ?

star-szr’s picture

Yeah for this particular issue that seems right. !important everything! :P

star-szr’s picture

We talked about this on the Twig call, it's not just a Seven issue. It will be an issue to anyone using Classy as a base theme. We talked about when you declare a CSS dependency it should (within the SMACSS group) alter the source order of the CSS, similar to how the JS dependencies work. We also talked about potentially re-purposing #2474091: CSS files from themes are being loaded in reversed order to discuss this ordering/dependency issue.

All of this should probably be on the parent issue but it's kinda too late. Sorry :(

star-szr’s picture

Another IRC discussion, getting pretty in depth so time to move this higher level discussion to the parent. In the meantime someone could try to implement what I've proposed as a straight hook_library_info_alter(), that would probably be a good POC.

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

almaudoh’s picture

@lauriii #4: All hope is not yet lost :) I've started some work over at #2451411: Add libraries-override to themes' *.info.yml. There's a patch now for testing and review.

On dependencies, AFAICS there is nothing in the codebase that points to ordering by SMACSS groupings, I could be wrong, so this actually needs some discussion.

mortendk’s picture

@cottser do we need a meta where we actually discuss how the css ordering should be ?
- this is gonna be an epic pita further down the road if we dont figure it out ... asap ;)

star-szr’s picture

I think the dependencies ordering deserves discussion but won't solve this.

What we want here is to append to libraries, not make them depend on classy. In their words we want core > classy > seven, not classy > core > seven.

mortendk’s picture

+1 cottser

star-szr’s picture

Status: Needs work » Needs review
FileSize
1.87 KB

Going to try and put a patch up here, in the meantime here's a reroll of #21.

star-szr’s picture

Since this one actually needs something like #2497667: Add libraries-extend to themes' *.info.yml and there's not even a patch there yet, here's a patch that should do the trick.

This gets the library definition from classy.libraries.yml and adds it to the 'theme' group in the existing user/drupal.user library, "extending it". Unfortunately getLibraryByName() returns the numeric constant for the group so I think 'theme' needs to be hardcoded.

The screenshot below shows 8.0.x vs. this patch, and that the CSS file is staying in the exact same spot:

Edited to link screenshot.

LewisNyman’s picture

Status: Needs review » Needs work

I can confirm this works as expected. The only thing we need to do it change the file to css/components/user.css

LewisNyman’s picture

Issue tags: +Novice
star-szr’s picture

Status: Needs work » Needs review
FileSize
2.14 KB
582 bytes

Sure, here's that change.

LewisNyman’s picture

Status: Needs review » Reviewed & tested by the community
Issue tags: -Novice

Great, thanks.

davidhernandez’s picture

+++ b/core/themes/classy/classy.libraries.yml
@@ -27,3 +27,9 @@ search.results:
+    theme:
+      css/components/user.css: {}

Same question that I've had on other issues. Should this go in a "theme" folder, since it is in the "theme" category.

RainbowArray’s picture

I think ideally we'll do a follow-up to clean up any inconsistencies if and when these all get in. We're essentially using the theme and component library groups as a way to keep the file loading order the same rather than a meaningful description of what those library elements do. It would be great to straighten that out, but I think it's more important to get the move done first.

davidhernandez’s picture

We're only going to get one chance at this, unfortunately. We're too close to RC to rely on follow ups.

Classy can have things added to it later, but I don't believe we'll be able to modify what is there come RC and release, so lets make sure we're getting it right when it first goes in.

I agree it should stay in the theme category. I'm suggesting the files go in a theme folder, instead of the components folder where the files that are added in the component category are stored.

LewisNyman’s picture

Status: Reviewed & tested by the community » Needs work
Issue tags: +Novice
+++ b/core/themes/classy/classy.libraries.yml
@@ -27,3 +27,9 @@ search.results:
+    theme:
+      css/components/user.css: {}

This is a component so we need to change this.

star-szr’s picture

That will mess with the loading order, won't it? This might be an exceptional case.

LewisNyman’s picture

@Cottser It will change the loading order. We've found in other issues like #2553461: Move system icons.theme.css, messages.theme.css, and progress.theme.css to Classy, this should ensure that it's loaded as early as possible.

rudraram’s picture

@LewisNyman So { weight: -10 } ensures the early loading of the file?

davidhernandez’s picture

The loading order is a combination of category (component, theme, etc) and weight. Also factored in is whether it is added from a module or theme. Files added from modules appear higher. All the "component" files added by themes are somewhat grouped together. The weight will make it get added higher in that grouping.

RainbowArray’s picture

LewisNyman’s picture

Status: Needs review » Reviewed & tested by the community
Issue tags: -Novice

Great, thank you.

star-szr’s picture

Status: Reviewed & tested by the community » Needs review

The hook library alter is putting it in the theme group, not component group.

LewisNyman’s picture

@Cottser Good catch. Here's an updated patch

gints.erglis’s picture

Status: Needs review » Needs work

patch does not apply

gints.erglis’s picture

Status: Needs work » Needs review
FileSize
2.17 KB
star-szr’s picture

Issue summary: View changes
Status: Needs review » Reviewed & tested by the community
FileSize
399.73 KB
94.54 KB
93.45 KB

The CSS does get moved up but there are no visual regressions, markup diff screenshot and before/after screenshots below. Back to RTBC, thanks!

Before:

After:

LewisNyman’s picture

Status: Reviewed & tested by the community » Postponed
star-szr’s picture

Issue summary: View changes
FileSize
236.85 KB

akalata’s picture

Status: Postponed » Closed (fixed)