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

CommentFileSizeAuthor
#54 interdiff.txt1.01 KBeffulgentsia
#54 3070493-54.patch49.39 KBeffulgentsia
#53 3070493-53.patch49.39 KBeffulgentsia
#42 3070493-41.patch49.35 KBbnjmnm
#42 interdiff_38-41.txt2.5 KBbnjmnm
#38 interdiff_36-38.txt622 bytesbnjmnm
#38 3070493-38.patch47.99 KBbnjmnm
#36 3070493-36.patch47.38 KBbnjmnm
#36 interdiff_33-36.patch8.37 KBbnjmnm
#33 3070493-33.patch78.95 KBbnjmnm
#33 interdiff_32-33.txt9.03 KBbnjmnm
#32 3070493-32.patch73.7 KBbnjmnm
#32 interdiff_28-32.txt1.35 KBbnjmnm
#28 interdiff_26-28.txt7.73 KBbnjmnm
#28 3070493-28.patch73.66 KBbnjmnm
#26 interdiff_24-26.txt70.21 KBbnjmnm
#26 3070493-26.patch70.2 KBbnjmnm
#24 3070493-24.patch97.18 KBbnjmnm
#22 3070493-module-specific-POC.patch120.09 KBbnjmnm
#15 interdiff_12-15.txt2.9 KBbnjmnm
#15 3070493-15.patch7.49 KBbnjmnm
#12 3070493-12-MODULE.patch5.82 KBbnjmnm
#9 3070493-9-PROOF-CONCEPT.patch5.16 KBbnjmnm
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

lauriii created an issue. See original summary.

lauriii’s picture

lauriii’s picture

Title: Add alternative toolbar design for Claro » Provide alternative design for Claro in Toolbar module
xjm’s picture

Is 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.

idebr’s picture

Is there a reason the designs can't be included in Claro, then added to Toolbar module when stable?

This 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.

lauriii’s picture

#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.

Version: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.0-alpha1 will be released the week of October 14th, 2019, which means new developments and disruptive changes should now be targeted against the 8.9.x-dev branch. (Any changes to 8.9.x will also be committed to 9.0.x in preparation for Drupal 9’s release, but some changes like significant feature additions will be deferred to 9.1.x.). For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

lauriii’s picture

Now 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.

bnjmnm’s picture

Version: 8.9.x-dev » 9.1.x-dev
Status: Active » Needs review
FileSize
5.16 KB

Although 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.

bnjmnm’s picture

Just thought of a cleaner way to implement #9. Move that to Claro.theme with a small change
change

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...

saschaeggi’s picture

@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.

bnjmnm’s picture

I 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.

front-end-library-access:
  - toolbar

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:

  1. Apply the patch
  2. Enable the claro_front_end module
  3. In claro.info.yml, there are several commented configurations in libraries-override: and libraries-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:

Status: Needs review » Needs work

The last submitted patch, 12: 3070493-12-MODULE.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

bnjmnm’s picture

Status: Needs work » Needs review

#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.

bnjmnm’s picture

This 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.

Status: Needs review » Needs work

The last submitted patch, 15: 3070493-15.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

bnjmnm’s picture

Status: Needs work » Needs review

Like 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.

lauriii’s picture

I 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:

  1. Option 1: Implement plan from #3103382: Allow specifying which theme should be used for rendering a render array which proposes architectural changes that would allow admin themes to take over the design of admin components on the frontend in a generic way.
    1. Pros
      1. Introduces a consistent pattern for rendering and theming admin components on the frontend
    2. Cons
      1. Complexity of the required changes and the new API
      2. Implementing this on time for Drupal 9.1 doesn’t seem feasible
  2. Option 2: Provide alternative designs in Toolbar, Quickedit, Contextual links, Media Library and Layout Builder. We would also have to find a place where alternative designs could be provided for Settings Tray.
    1. Pros
      1. Low level of complexity since no new APIs will get introduced
    2. Cons
      1. Possibility of dead code if Claro gets removed from core especially if not implemented as proposed in option 4
      2. Doesn’t provide a solution for the long term; what happens after Seven gets moved to contrib?
      3. Overriding libraries in a module is a deviation from a well-established pattern where libraries are only overridden by themes.
      4. Modal dialog and off-canvas dialog are not controlled by a module but core itself. These will need a different solution.
  3. Option 3: Add a new API that allows overriding frontend components in Claro as proposed in #15
    1. Pros
      1. Proof of concept exists
      2. Claro will be able to gain control of the design of these components
    2. Cons
      1. Possibility of dead code if Claro gets removed from core if not implemented as proposed in option 4
      2. The API allows taking over the libraries and templates module by module basis, which could be problematic with some modules that ship both, admin and frontend components. This could be solved by adding more granularity to the configuration
      3. Modal dialog and off-canvas dialog are not controlled by a module but core itself. These will need a different solution.
  4. Option 4: Implement option 2 or 3 so that they are shipped in a new module
    1. Pros
      1. Lower chance of ending up with dead code because the code is isolated
    2. Cons
      1. The module would have to be visible because modules cannot be enabled using the theme installer.
  5. Option 5: Implement option 3 but so that it’s generic and could be used by any admin theme
    1. Pros
      1. Potentially solves some problems mentioned in option 1 with less complexity
      2. Allows contrib admin themes to theme these components the same way as Claro 
    2. Cons
      1. This would probably have to be implemented inside theme system or system module for it to be available to all themes
      2. The proof of concept doesn’t give access to preprocess functions but this could be potentially added later
      3. Introduces a new API which will be potentially unnecessary in future if option 1 gets implemented. This is only a problem if this doesn’t manage solve all of the problems that option 1 tries to solve

Questions:

  1. Should admin themes be able to control admin components on the frontend? This includes Toolbar, Quick Edit, Contextual Links, Media Library, Layout Builder and Settings Tray.
  2. If needed, can we introduce a new visible module that supports Claro? Users will have to enable this module manually, prior to installing Claro since theme installer cannot install modules.
  3. Which of the proposed solutions seem most feasible?
Wim Leers’s picture

As 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 🤓

webchick’s picture

@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.)

Questions:
Should admin themes be able to control admin components on the frontend? This includes Toolbar, Quick Edit, Contextual Links, Media Library, Layout Builder and Settings Tray.

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.

If needed, can we introduce a new visible module that supports Claro? Users will have to enable this module manually, prior to installing Claro since theme installer cannot install modules.

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.

Which of the proposed solutions seem most feasible?

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.

shaal’s picture

bnjmnm’s picture

There 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

function _toolbar_is_claro_admin() {
   $admin_theme = \Drupal::configFactory()->get('system.theme')->get('admin');
   return !\Drupal::service('router.admin_context')->isAdminRoute() && $admin_theme === 'claro';
}

/**
 * Implements hook_library_info_alter().
 *
 * The default theme will use Claro's styles when Claro is the admin theme.
 */
function toolbar_library_info_alter(&$libraries, $extension) {
  if (_toolbar_is_claro_admin() && $extension === 'toolbar') {
    $toolbar_css = &$libraries['toolbar']['css'];
    $css_to_override = [
      'css/toolbar.module.css' => [
        'concern' => 'component',
        'new_key' => '/core/themes/claro/css/components/toolbar.module.css',
      ],
      'css/toolbar.theme.css' => [
        'concern' => 'theme',
        'new_key' => '/core/themes/claro/css/theme/toolbar.theme.css',
      ],
      'css/toolbar.icons.theme.css' => [
        'concern' => 'theme',
        'new_key' => '/core/themes/claro/css/theme/toolbar.icons.theme.css',
      ],
    ];
    foreach ($css_to_override as $old_key => $override) {
      $concern = $override['concern'];
      $asset_properties = $toolbar_css[$concern][$old_key];
      // Remove the existing toolbar CSS.
      unset($toolbar_css[$concern][$old_key]);

      // Add Claro's Toolbar CSS.
      $toolbar_css[$concern][$override['new_key']] = $asset_properties;
    }
  }
}

And inside template_preprocess_toolbar():

// If Claro is the admin theme, Toolbar will be styled by Claro and should
  // receive the same preprocessing it would in Claro.
  if (_toolbar_is_claro_admin()) {
    require_once DRUPAL_ROOT . '/core/themes/claro/claro.theme';
    claro_preprocess_toolbar($variables);
  }
effulgentsia’s picture

Status: Needs review » Needs work

+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:

  1. +++ b/core/modules/toolbar/toolbar.module
    @@ -290,3 +298,42 @@ function _toolbar_get_subtrees_hash() {
    +function toolbar_library_info_alter(&$libraries, $extension) {
    

    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.

  2. +++ b/core/modules/toolbar/toolbar.module
    @@ -290,3 +298,42 @@ function _toolbar_get_subtrees_hash() {
    +    $css_to_override = [
    +      'css/toolbar.module.css' => [
    +        'concern' => 'component',
    +        'new_key' => '/core/themes/claro/css/components/toolbar.module.css',
    +      ],
    +      'css/toolbar.theme.css' => [
    +        'concern' => 'theme',
    +        'new_key' => '/core/themes/claro/css/theme/toolbar.theme.css',
    +      ],
    +      'css/toolbar.icons.theme.css' => [
    +        'concern' => 'theme',
    +        'new_key' => '/core/themes/claro/css/theme/toolbar.icons.theme.css',
    +      ],
    +    ];
    

    This duplicates what's in claro.info.yml, so rather than duplicating it, how about parsing it from that file instead?

  3. +++ b/core/modules/toolbar/toolbar.module
    @@ -290,3 +298,42 @@ function _toolbar_get_subtrees_hash() {
    +   return !\Drupal::service('router.admin_context')->isAdminRoute() && $admin_theme === 'claro';
    

    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 checking ThemeManagerInterface::getActiveTheme()?

  4. +++ b/core/modules/toolbar/toolbar.module
    @@ -290,3 +298,42 @@ function _toolbar_get_subtrees_hash() {
    +function _toolbar_is_claro_admin() {
    

    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().

  5. +++ b/core/modules/toolbar/toolbar.module
    +++ b/core/modules/toolbar/toolbar.module
    @@ -129,6 +129,14 @@ function template_preprocess_toolbar(&$variables) {
    

    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.

  6. Because this patch adds logic that's conditional on whether Claro is the admin theme, we also need to add cache invalidation for when that changes. In the preprocess function, we need to add $variables['#cache']['tags'][] = 'config:system.theme'. And for the library_info_alter, we need to add an event subscriber for ConfigEvents::SAVE, to invalidate the 'library_info' cache tag if the admin theme got changed.
bnjmnm’s picture

To facilitate manual review this still includes the patch from #3020422: Toolbar style update

This is what is specific to this issue:
system.module

/**
 * Determines if Claro is the admin theme but not the active theme.
 *
 * @return boolean
 *   TRUE if Claro is the admin theme but not the active theme.
 */
function _system_is_claro_admin_and_not_active() {
  $admin_theme = \Drupal::configFactory()->get('system.theme')->get('admin');
  $active_theme = \Drupal::theme()->getActiveTheme()->getName();
  return $active_theme !== 'claro' && $admin_theme === 'claro';
}

/**
 * Implements hook_library_info_alter().
 */
function system_library_info_alter(&$libraries, $extension) {
  // If Claro is the admin theme but not the active theme, grant Claro the
  // ability to override the toolbar library with its own assets.
  if ($extension === 'toolbar' && _system_is_claro_admin_and_not_active()) {
    require_once DRUPAL_ROOT . '/core/themes/claro/claro.theme';
    claro_system_module_invoked_library_info_alter($libraries, $extension);
  }
}

/**
 * Implements hook_preprocess_toolbar().
 */
function system_preprocess_toolbar(array &$variables) {
  // If Claro is the admin theme but not the active theme, still include Claro's
  // toolbar preprocessing.
  if (_system_is_claro_admin_and_not_active()) {
    $variables['#cache']['tags'][] = 'config:system.theme';
    require_once DRUPAL_ROOT . '/core/themes/claro/claro.theme';
    claro_preprocess_toolbar($variables);
  }
}

claro.theme

/**
 * Called via system.module via its hook_library_info_alter().
 *
 * hook_library_info_alter() is not directly called in .theme files.
 */
function claro_system_module_invoked_library_info_alter(&$libraries, $extension) {
  if ($extension === 'toolbar') {
    $claro_info = \Drupal::service('theme_handler')->listInfo()['claro']->info;
    $path_prefix = '/core/themes/claro/';
    $claro_toolbar_overrides = $claro_info['libraries-override']['toolbar/toolbar'];
    foreach ($claro_toolbar_overrides['css'] as $concern => $overrides) {
      foreach ($claro_toolbar_overrides['css'][$concern] as $key => $value) {
        $config = $libraries['toolbar']['css'][$concern][$key];
        $libraries['toolbar']['css'][$concern][$path_prefix . $value] = $config;
        unset($libraries['toolbar']['css'][$concern][$key]);
      }
    }
  }
}

\Drupal\system\EventSubscriber\ConfigCacheTag

// Library overrides potentially change for the default theme when the admin
    // theme is changed.
    if ($config_name === 'system.theme' && $event->isChanged('admin')) {
      $this->cacheTagsInvalidator->invalidateTags(['library_info']);
    }
bnjmnm’s picture

Status: Needs work » Needs review
bnjmnm’s picture

This 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.

Status: Needs review » Needs work

The last submitted patch, 26: 3070493-26.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

bnjmnm’s picture

Status: Needs work » Needs review
FileSize
73.66 KB
7.73 KB

Made 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.

Status: Needs review » Needs work

The last submitted patch, 28: 3070493-28.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

bnjmnm’s picture

Status: Needs work » Needs review

fail in #28 was an unrelated test known to intermittently fail.

lauriii’s picture

+1 to removing the design changes from this issue to make this committable without having to review the design changes.

+++ b/core/modules/system/system.module
@@ -1250,3 +1250,40 @@ function system_modules_uninstalled($modules) {
+    claro_preprocess_toolbar($variables);

Should we pass rest of the arguments for the Claro preprocess function just to make the call closer to regular preprocess function calls?

bnjmnm’s picture

bnjmnm’s picture

The 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.

lauriii’s picture

Status: Needs review » Needs work
  1. +++ b/core/themes/claro/claro.theme
    @@ -1413,3 +1413,39 @@ function claro_preprocess_links__media_library_menu(array &$variables) {
    +/**
    + * Implements hook_preprocess_toolbar().
    + */
    +function claro_preprocess_toolbar(&$variables, $hook, $info) {
    

    We should document that this is called by system_preprocess_toolbar.

  2. +++ b/core/themes/claro/claro.theme
    @@ -1413,3 +1413,39 @@ function claro_preprocess_links__media_library_menu(array &$variables) {
    + * Called via system.module via its hook_library_info_alter().
    + *
    + * The library_info_alter() hook is not directly called in .theme files.
    

    It would be nice to have @see system_library_info_alter here too.

  3. +++ b/core/themes/claro/css/theme/toolbar.theme.pcss.css
    --- /dev/null
    +++ b/core/themes/claro/templates/navigation/menu--toolbar.html.twig
    
    +++ b/core/themes/claro/templates/navigation/menu--toolbar.html.twig
    --- /dev/null
    +++ b/core/themes/claro/templates/navigation/toolbar.html.twig
    

    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.

  4. I think we could make the patch easier to review by generating it with git diff -C -C. This should show some of the code as a copy in the patch.
lauriii’s picture

+++ b/core/modules/system/system.module
@@ -1250,3 +1250,55 @@ function system_modules_uninstalled($modules) {
+    $variables['#cache']['tags'][] = 'config:system.theme';

Shouldn't this be applied always because we should account to the scenario where Claro gets installed.

bnjmnm’s picture

Status: Needs work » Needs review
FileSize
8.37 KB
47.38 KB

Addresses #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()

Status: Needs review » Needs work

The last submitted patch, 36: 3070493-36.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

bnjmnm’s picture

Status: Needs work » Needs review
FileSize
47.99 KB
622 bytes

Adding the cachetag unconditionally required updating a test.

lauriii’s picture

Should 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.

lauriii’s picture

Discussed #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.

lauriii’s picture

  1. +++ b/core/modules/system/system.module
    @@ -1250,3 +1250,57 @@ function system_modules_uninstalled($modules) {
    +    claro_preprocess_toolbar($variables, $hook, $info);
    

    Do 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 and hook_library_info_alter?

  2. +++ b/core/modules/system/tests/src/Functional/Theme/ToolbarClaroOverridesTest.php
    @@ -0,0 +1,127 @@
    +    foreach ($claro_stylesheets as $stylesheet) {
    +      $this->assertStringContainsString($stylesheet, $head);
    +    }
    +    foreach ($default_stylesheets as $stylesheet) {
    +      $this->assertStringNotContainsString($stylesheet, $head);
    +    }
    

    Should we also confirm that the order of the stylesheets is correct?

bnjmnm’s picture

#41.1

Do 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 and hook_library_info_alter?

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.

lauriii’s picture

Status: Needs review » Reviewed & tested by the community

Makes sense 👍

I think this is ready for a final sign-off from a framework manager and release managers.

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 42: 3070493-41.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

bnjmnm’s picture

Status: Needs work » Reviewed & tested by the community

Test failure was an unrelated test known to randomly fail. Returning to prior status.

andrewmacpherson’s picture

What exactly is RTBC here?

  • There are no screenshots here. Surely we'd want those before RTBC if this is introduces a new design?
  • I'm confused about the relationship between this issue, and #3020422: Toolbar style update. Both issues have large patches, and they are touching many of the same files.
bnjmnm’s picture

There are no screenshots here. Surely we'd want those before RTBC if this is introduces a new design?

There'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.

'm confused about the relationship between this issue, and #3020422: Toolbar style update. Both issues have large patches, and they are touching many of the same files.

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.

andrewmacpherson’s picture

Thanks. 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?

Gábor Hojtsy’s picture

This still needs an issue summary update as to what is going on.

bnjmnm’s picture

Issue summary: View changes
Issue tags: -Needs issue summary update

I updated the issue summary.

Re: #48

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?

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.

Gábor Hojtsy’s picture

Title: Provide alternative design for Claro in Toolbar module » Introduce a mechanism to provide an alternate Claro design for the toolbar in the future

Retitling based on that. Noticed the release/framework manager signoffs are not yet provided, so cannot commit.

Version: 9.1.x-dev » 9.2.x-dev

Drupal 9.1.0-alpha1 will be released the week of October 19, 2020, which means new developments and disruptive changes should now be targeted for the 9.2.x-dev branch. For more information see the Drupal 9 minor version schedule and the Allowed changes during the Drupal 9 release cycle.

effulgentsia’s picture

Reroll.

effulgentsia’s picture

With 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.

  • effulgentsia committed 65958f9 on 9.2.x
    Issue #3070493 by bnjmnm, lauriii: Introduce a mechanism to provide an...

  • effulgentsia committed b5941f6 on 9.1.x
    Issue #3070493 by bnjmnm, lauriii: Introduce a mechanism to provide an...
effulgentsia’s picture

Version: 9.2.x-dev » 9.1.x-dev
Status: Reviewed & tested by the community » Fixed

Pushed to 9.2.x and 9.1.x.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.