Problem/Motivation
Claro is new admin theme built as part of the Admin UI and JavaScript modernization initiative. As part of the project, we've worked on redesigning the toolbar: #3020422: Toolbar style update. While working on that issue we run into the issue that admin themes are unable to control the design of toolbar globally: #2539992: Move theme toolbar CSS to the Seven theme i.e., if the admin theme such as Claro has restyled the toolbar, a non-Claro default theme would not receive these toolbar styles. This would result in an inconsistent user experience that would fail to meet several of Neilsen's heuristics.
Proposed resolution
Add logic to system.module that only executes if
- Claro is the admin theme
- The user is on a page using the default theme, and the default theme is not Claro
When these conditions are met, The CSS and twig assets that would typically be loaded from the Toolbar module will instead be loaded with corresponding assets from Claro.
For the purposes of this issue, the assets loading from Claro will be largely identical to those in the toolbar module. The only differences should be small modifications that don't impact functionality and can be used to confirm the file being loaded, and the adjustment of any relative paths due to the file's location.
Remaining tasks
User interface changes
None. The Toolbar experience itself will be unchanged. The CSS and templates will be loaded from a different path, but the end result will be identical.
API changes
Data model changes
Release notes snippet
Comment | File | Size | Author |
---|---|---|---|
#54 | interdiff.txt | 1.01 KB | effulgentsia |
#54 | 3070493-54.patch | 49.39 KB | effulgentsia |
#53 | 3070493-53.patch | 49.39 KB | effulgentsia |
#42 | 3070493-41.patch | 49.35 KB | bnjmnm |
#42 | interdiff_38-41.txt | 2.5 KB | bnjmnm |
Comments
Comment #2
lauriiiComment #3
lauriiiComment #4
xjmIs there a reason the designs can't be included in Claro, then added to Toolbar module when stable? That's what we typically do when experimental modules need to add to themes. They ship the templates and CSS themselves initially, and then they're copied to the appropriate theme when stable.
We do have one or two past example I can think of where we referenced something less stable or not in core, but those were situations where we had to in order to avoid incompatible modules from being enabled and it's something we try to avoid.
Comment #5
idebr CreditAttribution: idebr at iO commentedThis would work for Claro when its included in Drupal Core. However, if I am interpreting the proposed resolution correctly, laurii suggests adding an API to render elements in the Admin theme (eg. Claro) when viewing a page that is not the current admin theme (eg. Bartik). This would then enable contrib admin themes (eg. Adminimal) to apply their styling to the Toolbar as well.
Comment #6
lauriii#3020422: Toolbar style update is suggesting to add an API so that admin themes could globally control the design of the toolbar. However, that issue has been blocked for years, and for that reason, I would prefer if we could move forward without solving that issue.
The reason we can't include Toolbar designs in Claro is that there's no existing API to override templates or assets globally. If we override the toolbar templates and CSS the way we would usually do, it results in Toolbar having different design depending on which theme the page is rendered with. I know this issue is specific to Toolbar, but we will redesigning Settings Tray and Contextual links are blocked by this same issue.
Comment #8
lauriiiNow that #474684: Allow themes to declare dependencies on modules has landed, alternative solution to what has been proposed earlier would be to create a new module that would be responsible for adding Claro specific styles for Toolbar, Quickedit, Contextual links, Settings Tray etc.
Comment #9
bnjmnmAlthough it's now possible for themes to declare dependencies on Modules, it's not currently possible to enable those depended-upon modules as part of enabling the theme. Were a module to do this it would probably work best as a hidden one, but this couldn't happen since it would need to be explicitly enabled.
Because of this, I'm more inclined to go with a customization to an existing module.
This patch adds logic to toolbar.module that makes it possible to override and extend toolbar libraries like any other library, but it will be applied to the front end theme as well. This could pretty easily be moved to a module or somewhere else centralized as very little about it is toolbar-specific.
Comment #10
bnjmnmJust thought of a cleaner way to implement #9. Move that to Claro.theme with a small changechange
if ($extension === 'toolbar' && !\Drupal::service('router.admin_context')->isAdminRoute() && $admin_theme === 'claro') {
to
if (in_array($extension, $modules_claro_can_style_on_fe) && !\Drupal::service('router.admin_context')->isAdminRoute() && $admin_theme === 'claro') {
That way, if Claro needs the ability to style additional modules on the front end, it only requires adding a new item to the$modules_claro_can_style_on_fe
array.(if this hook doesn't fire in .theme files, that can be changed pretty easily)If that approach works this can probably be re-scoped to Claro.EDIT: that wont work - those hooks don't fire when it isn't the active theme (got thrown because the libraries are available)
The ease in which a new module can be added seems to favor using this approach in a module. My concern about the module won't really be an issue once Claro is the default admin theme...
Comment #11
saschaeggi@bnjmnm what if we add an module which basically just adds the toolbar stylesheet to the frontend when the user is logged in? So everything stays in Claro itself (more of a workaround until it's the default theme) and it can be deprecated later on.
That's the approach I've done with Gin & Gin_toolbar. Toolbar is a module which injects the toolbar CSS from the Gin theme.
You could check & inject that via the toolbar module.
Comment #12
bnjmnmI took a cue from #11 and created a module. This patch includes that and some extra code to enable manual review.
Any modules that Claro should have access to should be specified in claro.info.yml via the
front-end-library-access:
property.If this is specified, then all of Claro's libraries-override and libraries-extend will modify those module's libraries on front end as well.
To try this out:
libraries-override:
andlibraries-extend:
that provide examples of this module working. Uncomment and clear cache to see examples of extending and overriding in different ways.This approach means that when it comes time for Claro to modify quickedit, contextual links, etc, they will have that ability by adding the module to
front-end-library-access:
Comment #14
bnjmnm#12 failed tests as it adds a new module but the composer part hasn't been done. This can still be manually tested and should get that before anything additional is done.
Comment #15
bnjmnmThis adds the ability for Claro to override templates as well. It will only do this to templates that were added to the registry in modules specified in
front-end-library-access:
. This may get ugly if it was necessary to do something from the system module, but there are other ways to implement this if that seems needed.Comment #17
bnjmnmLike previously mentioned in #14, these test failures are due to not integrating composer yet. Switching to Needs Review as what is there does merit review as it proves the concept of Claro being able to selectively control front end libraries and templates.
Comment #18
lauriiiI worked on identifying possible ways to move forward on this with @bnjmnm. It doesn't seem like there's a solution that would come without any down sides.
Possible solutions:
Questions:
Comment #19
Wim LeersAs one of the people involved with the current Toolbar module: I just found this issue, I'm following it, feel free to ping me to help you find pointers for original design decisions. I can't promise anything, but I can probably help you find answers a bit faster 🤓
Comment #20
webchick@lauriii reviewed this with Gábor and I on the Monthly Cross-Core Collaboration meeting. (Only speaking for myself here, but did run this past Gábor and he agreed.)
I don't think I can speak to actual implementation of the solution, but the problem being raised, where depending on what path you're on, you see one style of toolbar/etc. or another, is extremely disruptive to the overall user experience, so huge +1 to fixing it. It's an enormous visual regression otherwise, and seems borderline critical.
Logically though, it does make a lot of sense that the themes (+ theme-related modules) would be responsible for the styling, vs. functional modules. So +1 to the general gist of this issue.
Hm. I'm really sorry, but that does not sound like acceptable UX to me, unless there were zero other options of getting Claro out in time for 9.1. :\
Because people generally do not read docs, they will naturally go to Admin > Appearance to adjust their theme and expect that when they check-off Claro it will "just work." (Just like if you check off "Migrate Drupal UI" in modules, it will automatically enable the dependent modules that it needs to function.) We would need some kind of kludgey UI-based workaround to circumvent this natural behaviour (For example, greying out the ability to install, supplementing it with help text that directs them back to the modules page with manual instructions on what to do once they're there), and rather than bikeshedding about what that kludgey workaround is/could be, it would be way preferable to just fix the underlying issue that is forcing this workflow.
It sounds like the "automatically enable dependencies" bit was de-scoped from the original "let themes depend on modules" patch. It would be great to try and understand what the "level of effort" would be to implement that missing piece, because that seems like it would help not only Claro but also any contrib/custom theme that wants to also depend on a module. This also prevents the need of inventing + testing + documenting some new API for this.
In other words, Option 4 without the cons would be my vote, FWIW. :) Better still if the underlying module dependency can be hidden, but not a hard requirement.
Two other "product management-y" things:
1. I see several cons in the list that relate to contingency planning if Claro one day gets removed. From a product management POV, that is not going to happen. We demonstrated "beyond a reasonable doubt" back when we last surveyed the community in 2018 to determine why D8 was not being adopted, that the lack of a modern admin experience is one of the top reasons, and so even if Claro dithered around in beta for another 8 releases (hopefully not :)), we would not want to remove it from core. We need it in order to increase Drupal adoption, the accessibility improvements are already light-years beyond Seven, multiple high-profile contrib modules such as Webform have already done integration work with it, and there are not exactly a swarm of competing initiatives trying to also update Drupal's admin theme. :P So our assumptions when comparing/contrasting solutions should proceed along the lines that Claro is going to replace Seven as the default admin theme at some point in the D9 cycle, and that the sooner that happens, the better for everyone.
2. We should also recognize that the number of people who are going to write admin themes, and esp. admin themes that are extremely opinionated on what "admin-y" front-end elements like Toolbar, etc. look like, is infinitesimally small. We can count those projects on one hand. We should therefore be careful about the "perfect being the enemy of the good" in this regard. There is far, far greater value to Drupal to Claro being in the hands of site builders sooner than later vs. having the perfectly architected solution for this particular edge case.
Comment #21
shaal#20 +1
I think this issue #3100374: Make it possible to install dependent modules when installing theme will make "option 4 without the cons" - possible.
Comment #22
bnjmnmThere was interest in a proof of concept for loading Claro assets in FE themes on a per-module basis. This patch is a proof of concept for Toolbar, and includes a Claro toolbar patch from #3020422: Toolbar style update. The patch itself is large due to including the Claro styles, but the approach itself is only a few changes in toolbar.module
And inside
template_preprocess_toolbar()
:Comment #23
effulgentsia CreditAttribution: effulgentsia at Acquia commented+1 to proceeding with something along the lines of #22 rather than postponing this on #3100374: Make it possible to install dependent modules when installing theme. In terms of implementation:
Rather than inlining the implementation into this function, let's have this call
claro_library_info_alter()
and put the implementation there. However, in that case it would be that function checking$extension === 'toolbar'
, which means this wrapper function more properly belongs in system.module.This duplicates what's in
claro.info.yml
, so rather than duplicating it, how about parsing it from that file instead?I think the intent here is to return true when Claro is the admin theme and not the active theme, because if it's the active theme, then the theme system is already making it participate in preprocessing and library overriding. However,
!isAdminRoute()
isn't a sufficient guarantee that it's not the active theme. What if Claro is also set as the front-end theme? Or, what if a theme negotiator decides to use Claro for a non-admin route? So instead of checking for admin route, what about checkingThemeManagerInterface::getActiveTheme()
?If we're moving toolbar_library_info_alter() to system_library_info_alter(), then this needs to move to system.module as well. Also, per above, we're not just checking that claro is the admin theme, but also that it's not the active theme, so perhaps rename to
_system_is_claro_admin_and_not_active()
or_system_claro_is_inactive_admin_theme()
.If we move _toolbar_is_claro_admin() to system.module, then we should probably move this function's additions to
system_preprocess_toolbar()
as well. Which also has the benefit that if in other issues we need to implement preprocess wrappers for other (non-toolbar) components, then they can all be centralized in system.module.$variables['#cache']['tags'][] = 'config:system.theme'
. And for the library_info_alter, we need to add an event subscriber forConfigEvents::SAVE
, to invalidate the 'library_info' cache tag if the admin theme got changed.Comment #24
bnjmnmTo facilitate manual review this still includes the patch from #3020422: Toolbar style update
This is what is specific to this issue:
system.module
claro.theme
\Drupal\system\EventSubscriber\ConfigCacheTag
Comment #25
bnjmnmComment #26
bnjmnmThis adds tests and makes the patch reviewable and committable without having to add or consult #3020422: Toolbar style update. Claro does override three toolbar CSS files, but the files they are overridden with are copied from system module, and only edited to change the relative paths of background images. The toolbar styles are unchanged, but they now come from files located in Claro.
Comment #28
bnjmnmMade some changes so my locally-passing tests don't fail on DrupalCI like they did in #26.
Also expanded the functionality to include toolbar.menu.css as that's been added to the scope of #3020422: Toolbar style update, and this is reflected in the tests.
Comment #30
bnjmnmfail in #28 was an unrelated test known to intermittently fail.
Comment #31
lauriii+1 to removing the design changes from this issue to make this committable without having to review the design changes.
Should we pass rest of the arguments for the Claro preprocess function just to make the call closer to regular preprocess function calls?
Comment #32
bnjmnmAddresses #31
Comment #33
bnjmnmThe issue #3020422: Toolbar style update will also be overriding templates, so that has been added to the scope here, and the test coverage was expanded to reflect that addition.
Comment #34
lauriiiWe should document that this is called by
system_preprocess_toolbar
.It would be nice to have
@see system_library_info_alter
here too.Let's document in these files that these files are loaded by system module when Claro is admin theme even when Claro isn't the active theme.
git diff -C -C
. This should show some of the code as a copy in the patch.Comment #35
lauriiiShouldn't this be applied always because we should account to the scenario where Claro gets installed.
Comment #36
bnjmnmAddresses #34 and #35 plus a few CS nits, added a missing toolbar.menu.pcss.css (previously only the .css had been added), and moved some of the logic in system_theme_registry_alter() to claro.theme, similar to the pattern used by system_library_info_alter()
Comment #38
bnjmnmAdding the cachetag unconditionally required updating a test.
Comment #39
lauriiiShould this work with subthemes of Claro or should we document explicitly that it isn't a supported use case? I personally think it's fine to limit this for Claro just for the sake of simplicity. Adminimal and Gin (subtheme of Claro) already have workarounds for shipping redesigns of Toolbar.
Comment #40
lauriiiDiscussed #39 with @webchick and @bnjmnm. Claro doesn't officially support subthemes and the change doesn't break the approach used by Gin, one of the popular subthemes of Claro. Given that contrib themes already have a workaround in place, and that the solution here doesn't interfere with that, we agreed it would be fine to move forward with the patch without having support for subthemes for now. This is something that should be solved by #3103382: Allow specifying which theme should be used for rendering a render array.
Comment #41
lauriiiDo we have a specific reason we haven't used same pattern for naming the claro_preprocess_toolbar as we have for the
hook_registry_alter
andhook_library_info_alter
?Should we also confirm that the order of the stylesheets is correct?
Comment #42
bnjmnm#41.1
Yes, claro_preprocess_toolbar is used by both Claro and the non-Claro default theme using Claro's toolbar styles. The hook_registry_alter and hook_library_info_alter implementations are not needed by Claro, only by the non-Claro default theme. The reason for placing the functions in claro.theme can be found in #23
#41.2 The test was expanded to cover stylesheet loading order.
Comment #43
lauriiiMakes sense 👍
I think this is ready for a final sign-off from a framework manager and release managers.
Comment #45
bnjmnmTest failure was an unrelated test known to randomly fail. Returning to prior status.
Comment #46
andrewmacpherson CreditAttribution: andrewmacpherson as a volunteer commentedWhat exactly is RTBC here?
Comment #47
bnjmnmThere's no new design in this patch. This adds functionality where - if Claro is the admin theme - Claro will style the toolbar in the default theme as well, whether or not the default theme is Claro. This makes it possible for Claro to update the toolbar styles and have them be consistent whether or not the user is visiting admin pages.
Now that you mention it, this distinction doesn't seem like it would be clear to those who haven't been working closely on these issues. Tagging with "Needs issue summary update". It may be me doing the IS update, but can't at this moment.
Comment #48
andrewmacpherson CreditAttribution: andrewmacpherson as a volunteer commentedThanks. So this is the underlying mechanism to load libraries? I think I made a suggestion for such a thing elsewhere, a while back.
Will this work for any admin theme, such as those provided by some distros?
Comment #49
Gábor HojtsyThis still needs an issue summary update as to what is going on.
Comment #50
bnjmnmI updated the issue summary.
Re: #48
Not in the scope of this issue, this is specific to just Toolbar CSS/Templates, and only when Claro is the admin theme. #20 elaborates on why this approach is favored over waiting on the implementation of broader solutions such as #2195695: Admin UIs on the front-end are difficult to theme or #2632584: Add a "public admin" theme subtype so that admin themes can have subthemes for front-end UI components.
Comment #51
Gábor HojtsyRetitling based on that. Noticed the release/framework manager signoffs are not yet provided, so cannot commit.
Comment #53
effulgentsia CreditAttribution: effulgentsia at Acquia commentedReroll.
Comment #54
effulgentsia CreditAttribution: effulgentsia at Acquia commentedWith the current scope of this issue, I don't see any release management implications to this patch, so removing the need for release manager review.
This looks good to me from a framework management perspective, so removing that tag too.
Here's some trivial whitespace changes for coding standards.
Comment #57
effulgentsia CreditAttribution: effulgentsia at Acquia commentedPushed to 9.2.x and 9.1.x.