Problem/Motivation
As stated in #3050389: [META] Remove dependency to Classy from core themes, Classy will be moved to contrib before Drupal 9 and we have to remove dependencies on Classy from all core themes.
Part of this process includes creating theme-specific copies of all Classy libraries to core themes. This ensures Classy can be removed without impacting those themes.
Because this is the first of several issues for copying a Classy library to Umami, there are no tests for this yet.
Also because this is the first of several similar issues, this will also be used to collect feedback about the process and naming conventions, with the goal of making the additional issues as easy as possible to patch and review.
Proposed resolution
- Make an Umami-specific copy of
classy/dropbuttonThis includes:- The library should be called
classy.dropbutton, using theclassy.prefix to make it clear that it is copied from Classy, not custom to Umami - Umami should extend
core/drupal.dropbuttonso the end result behaves identically to Classy's extending of the library. - The CSS file will be located in
css/classy/components. As a rule, copied assets from Classy should go in aclassysubdirectory of that asset type, but otherwise maintain the directory structure from classy (such as going in a components or theme directory)
- The library should be called
- Add a test class that confirms the copy is successful, and build it so it is easily capable of testing other libraries when they are copied to a theme that previously depended on the Classy library.
- Manually test in Umami by comparing elements that use the dropbutton css before-patch and after-patch, and provide screenshots.
Remaining tasks
Currently all the steps above.
User interface changes
no
API changes
no
Data model changes
no
Release notes snippet
...
| Comment | File | Size | Author |
|---|---|---|---|
| #42 | 3096203-42.patch | 23.43 KB | bnjmnm |
| #42 | interdiff_40-42.txt | 3.13 KB | bnjmnm |
| #40 | 3096203-40.patch | 23.42 KB | bnjmnm |
| #40 | interdiff_38-40.txt | 729 bytes | bnjmnm |
| #38 | 3096203-38.patch | 23.56 KB | bnjmnm |
Comments
Comment #2
bnjmnmThis patch creates an Umami equivalent of


classy/dropbutton.Screenshots of manual testing:
Before
After


This also adds a test that can be used for all additional issues for copying other Classy libraries to Umami. For each libraries' issue, the library will be removed from the $librariesToSkip array. Several intended-to-fail patches are attached to demonstrate the various copying errors that are checked for.
Comment #3
bnjmnmRefactored the test to work with all core themes. As issues are opened to copy additional libraries, those libraries are removed from the "skip" array for that theme.
Also added checks in the test to confirm that if a Classy library is overridden, all CSS/JS files are accounted for.
Comment #8
lauriiiShould we also add a library override to unload the library from Classy? If we don't unload the Classy library, we would have two versions of the CSS loaded until we have removed dependency to Classy.
Comment #9
bnjmnmFrom #8
Good catch. That step has been added to the test coverage with a failing patch to prove it, along with a version that properly overrides the library.
Comment #12
bnjmnmAddresses the test failures in #9 by setting the libraries-override to the Umami library instead of FALSE.
Comment #13
lauriiiNit: s/css/CSS
These assertions are never run given that we skip this if the library has been overridden.
This seems redundant given that we never run this assert if the library has been overridden 🤔
Should we add more specific assertions for this scenario?
Comment #14
bnjmnmThis addresses all the points in #14. The feedback made it apparent that there was a better way to check for Classy libraries already fully-overridden by a theme. This means I was able to remove a few more libraries from the skip-lists as they are already entirely overridden in the Classy inheriting themes.
Comment #15
lauriiiI tested manually various use cases to ensure that the tests fail when libraries are not sufficiently overridden. I tried missing override on a library that was extended, as well as libraries with both CSS and JavaScript dependencies. Looks good to me! 🚀
Comment #16
xjmThanks for all the excellent test patches exposing the specific fails!
Reviewed so far by:
core/themes/classy/css/components/dropbutton.csstocore/profiles/demo_umami/themes/umami/css/classy/components/with the patch applied to verify that the files are identical.Failure message
Failure message:
Failure message:
Failure message:
Next doing a line-by-line CR of the patch...
Comment #17
xjmStarted a code review. Overall this test is excellent and thorough. I got kind of lost in the reviewing the method so I think there's some potential to simplify it with refactoring. Haven't finished reviewing yet but here are my notes so far (didn't want to lose them):
Does the theme decoupling depend on this negative weight for the overridden library? If so, this would be important to document in both the decoupling instructions and the CR.
General obeservation: This test method is really long. Can we factor it into smaller helper methods or such?
Also, should/could some of the initializations we use over and over that don't change be moved to
setUp()?Is the idea that we will update this variable as we complete the decoupling of each core library? So it'll eventually be a fairly long array?
Does it mean libraries fully overridden for just one theme, or all core themes?
I think we should add an inline comment explaining this array.
So this is a bit confusing. (Needs followup for the documentation of getLibrariesOverride, which doesn't explain the return structure at all.) If these are already the library overrides for this theme, as per the previous line, why are we checking the top-level key of the array for the path of the theme?
This could maybe use an inline comment.
Also,
$library_overridesisn't used again (except when it's re-initialized later in the method; see later point). Should we avoid the extra variable definition?Nit about the variable naming: Doesn't
$theme_at the start of the variable name mean the theme name passed in at the start of the method? Do we need a$this_theme_here? Otherwise it makes it seem like it's something different. Maybe we could use$this_theme_everywhere?I had to read this time several times to figure out where it was going. So this line is going over the list of library overrides, and checking for whether they're either on the list of libraries to skip (which is passed into the method from the data provider), or whether it already has classy in its library name (which means... that it's already in the Classy subdirectory?... and then only proceeding if neither of those conditions are true.
Could use an inline comment.
Didn't we already
foreachthis above with a different compoundcontinue? I wonder if there's a way to simplify the method structure.Aren't these two lines already at the start of the method? Why are we overwriting them here?
If they're overwritten but the same, we can delete these two lines and move the inline comment above them to the top of the method. If they're being overwritten and changing, that's a bit brittle and we should change it.
Comment #18
xjmEdit: Duplicate post.
Comment #19
xjm@bnjmnm is working on a new patch, so updating issue status to reflect that.
Comment #20
bnjmnm#17.1
The test has been expanded to check that weights and other asset properties match when it's a library copied from Classy
#17.2-8
That is a legit observation, it's unwieldy! I split this into two separate tests and several helper methods, and in doing so addressed the other feedback items. It should be easier to navigate now, although it's still a bit of a chungus.
Since this was a big refactor, I've provided failing tests for each major assertion in the tests.
3096203-20-theme-is-extending-with-classy-library-FAIL.patch
Error:
Triggered by:
Extending a core module library with a Classy library
3096203-20-core-lib-override-has-classy-asset-FAIL.patch
Error:
Triggered by:
The library loads a css file from Classy
3096203-20-incorrectly-override-core-lib-with-classy-lib-FAIL.patch
Error:
Triggered by:
In Claro, override user/drupal.user with classy/user
3096203-20-classy-extends-corelib-but-theme-does-not-FAIL.patch
Error:
Triggered by
user/drupal.user is removed from skip-list for Umami, so the test includes it as one of the Classy extends of a core library that must now be present in Umami
3096203-20-incomplete-asset-copy-FAIL.patch
Error:
Triggered by:
Changed the filename in the Umami library definition so the test thinks there is not a theme-specific copy of Classy's dropbutton.css
3096203-20-asset-properties-dont-match-FAIL.patch
Error:
Triggered by:
dropbutton.css has a weight of -11, which differ's from Classy's weight of -10
3096203-20-missing-copied-library-FAIL.patch
Error:
Triggered by:
Commented out the umami/classy.dropbutton library that should replace classy/dropbutton.
3096203-20-missing-equivalent-file-FAIL.patch
Error:
Triggered by:
Removed claro/base from the skip list. This library is overridden, but not all files are included in the override, so some Classy ones get through.
3096203-20-missing-library-override-FAIL.patch
Error:
Triggered by
Commented out the override of classy/dropbutton
Comment #30
xjm+1 for the refactor; much easier to read.
A few nits and inane observations:
Still confused here... what are "some cases"?
Null coalescing operator, fancy!
Missing underscore for
$library_assets.Nit: I think we should use single quotes rather than backticks around 'css', because the array key is an actual string.
Comment #31
xjmThanks 💯for the clear fail patches and explanations; definitely a big help for reviewing the issue.
Comment #32
xjmSome docblock nits:
Now that we have these, I think extending the docblocks here a little would help make the whole test easier to grok. Edit: Plus an
@seeto the API method returning the arrays (if such exists) is nice.Can we use a more specific data type than
array, e.g.array[],string[][], etc.?When test methods have a data provider, I like adding parameter documentation since that documents the data in the data provider nicely.
Ubernit: "Classy" with a capital C.
It's the path to the theme being tested, correct?
Comment #33
xjmUbernit: "CSS and "JS" capitalized, since they're words in a sentence rather than a string literal here.
💯 for starting off assertions like these to avoid false positives or weird fails later. Nice and robust.
So based on this
$item['data']is clearly a string, if that helps with the answer to my array type docs questions.Oops... in the assertion message, isn't it either CSS or JS? Or am I confused?
Comment #34
xjmI guess part of where my theme-noob questions come into play is that I'm unfamiliar with what the difference is for a library to be "overridden" versus "extended". Is this terminology documented somewhere? I think that explanation in context will make everything else in the test easier to follow. A simple example in each case might help.
"active theme" again, which means something site-config-specific to me. In the comments above, we're saying "current theme". We're talking about the same thing, right? The theme as named in
$theme, which is the theme currently being tested?Hrm? I'm guessing this means that the item will contain string data as opposed to
FALSEorNULL? Could use explanation.Bug in the assertion message I think; shouldn't it be
$js_file?Comment #35
xjmThat's probably enough small feedback to merit a NW. Now I've read all the lines of the latest patch. :)
Comment #36
bnjmnmThis addresses #30, #32, #33, #34. 🤞that the additional documentation helps more than confuses...
Comment #37
lauriiiThank you @bnjmnm for adding all the documenation! It makes understanding this test much easier 👏
Should we document that this is specifically added to facilitate the process of decoupling from Classy and that this may be removed later?
Why are we checking this again? Isn't the previous check already enough?
This comment is a bit confusing. It would be also useful if this would include explanation on to why we are not adding these libraries to the array.
Nit pick: Classy with capital. 🔬👁
Comment #38
bnjmnmAddresses #37
Comment #39
lauriiiI'm not sure if we actually want hold removing this test until Classy is removed. It might make sense to allow themes to make changes to these library configuration before that. This could be discussed in a follow-up issue so maybe we just omit this piece of information now. I think this can be done on commit.
Besides that, this looks great ✨
Comment #40
bnjmnmHere's an updated patch in case it can't be done on commit.
Comment #41
xjmIt should be "its" rather than "it's" in this sentence. ("It's" == "it is" but not "belonging to it".)
Also, comma splice. I'd put a period after "assets" and then just capitalized "these" for a new sentence.
For parallelism and agreement with "by", the first item should be "The current theme extending the core library..." (rather than "extends").
Same question about the specific array structure. We can at least say
array[]. (Or maybemixed[][], but the latter only occurs three times in core, so we can probably stick witharray[].)This could also be
array[]based on the values.These fixes are small enough that uploading a new patch at RTBC would be fine.
Comment #42
bnjmnmAddresses #41
Comment #43
xjmSaving issue credit.
Comment #46
xjmCommitted to 9.0.x, and backported to 8.9.x also so that the diff between the branches is meaningful for the test. Thanks!