Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Problem/Motivation
When possible, we shouldn't attach CSS or JS files, but asset libraries instead.
user_page_attachments()
attaches user.module.css
, but that's also part of the user/drupal.user
library, so it should attach that instead.
But, there is *nothing* in user.module.css
that is generically applicable to all pages, yet it is loaded on all pages. It's only necessary for:
- the permissions configuration UI (for which only
user/drupal.user.permissions
is loaded currently, it just happens to be the case thatuser.module.css
is loaded on all pages and hence happens to be correct - the account settings form (
AccountSettingsForm
). - user module's automatic enhancements for
#type => 'password'
element (to show password strength hints)
Proposed resolution
- Split up the CSS file into a
user.admin.css
one for point 1, to be compliant with https://www.drupal.org/node/1887922. We'll call this librarydrupal.user.admin
. We then attach that library toAccountSettingsForm
. This gets added to thedrupal.user.permissions
library that already exists. - And the rest stays as is.
Now there is no more need to load user.module.css
on every page! :)
Remaining tasks
None.
User interface changes
None.
API changes
None.
Comment | File | Size | Author |
---|---|---|---|
#1 | 2368739-1.patch | 3.4 KB | Wim Leers |
Comments
Comment #1
Wim LeersComment #2
Wim LeersComment #3
catchLooks great, I noticed this the other week when reviewing CSS loaded every page, and couldn't see anything in there that would make that necessary but failed to open an issue. RTBC.
Comment #4
catchComment #5
webchickNice catch. Since this is both a bug fix and about markup, which isn't currently locked down, this seems to good to go according to https://www.drupal.org/contribute/core/beta-changes.
Committed and pushed to 8.0.x. Thanks!
Comment #8
YesCT CreditAttribution: YesCT commentedchanging to use the more common tag, so the less common one can be deleted, so it does not show up in the auto complete and confuse people.