CiviCRM Administration Theme not selected

Created on 28 September 2023, about 1 year ago
Updated 4 October 2023, about 1 year ago

Problem/Motivation

Theme switching does not select for CiviCRM routes, selecting only the default frontend theme, not the administration theme.

Steps to reproduce

Use domain_theme_switch in a CiviCRM enabled environment.

Proposed resolution

Add logic to select civicrm route in RouteMatchInterface

Remaining tasks

User interface changes

API changes

Data model changes

Here's the code, added as the first check:

// Check if the current route belongs to CiviCRM admin.
$route_name = $route_match->getRouteName();
if (strpos($route_name, 'civicrm.') === 0) {
// This is a CiviCRM route. You can further refine this check if necessary.
return TRUE;
}

✨ Feature request
Status

Closed: works as designed

Version

1.0

Component

Code

Created by

πŸ‡΅πŸ‡·Puerto Rico Jaime_Pomales

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

  • Issue created by @Jaime_Pomales
  • Status changed to Postponed: needs info about 1 year ago
  • πŸ‡ΊπŸ‡¦Ukraine abramm Lutsk

    Hi Jaime_Pomales,
    I don't thing the module should include any quirks for other modules, being it civicrm, commerce, or anything else; that's just outside of its scope.

    You have a few options options here:
    1) Either submit a patch enabling flexible configuration (which would in turn allow you configuring the module the way you need it).
    or
    2) Submit the patch extending the ThemeSwitchNegotiator with a new event which could be dispatched in applies() which you could then subscribe to in your own custom code.

  • πŸ‡΅πŸ‡·Puerto Rico Jaime_Pomales

    Yes, I think you raise a fair point.

    I'll give it some thought and see what I can do.

  • πŸ‡΅πŸ‡·Puerto Rico Jaime_Pomales

    After some investigation, perhaps maybe just modifying the theme priority:

    services:
      theme.negotiator.domain_theme_switch:
        class: Drupal\domain_theme_switch\Theme\ThemeSwitchNegotiator
        arguments: ['@router.admin_context','@current_user','@domain.negotiator','@config.factory']
        tags:
          - { name: theme_negotiator, priority: 10 }

    By changing priority to 0 theme switcher should respect other theme route priorities over itself, especially an admin theme.

    After I changed my installation to priority 0 the admin theme is respected by domain_theme_switcher when in civicrm's admin area.

  • πŸ‡ΊπŸ‡¦Ukraine abramm Lutsk

    That really sounds like a breaking change and would definitely affect other users.

    I'd suggest just altering services on your side ( https://www.drupal.org/docs/drupal-apis/services-and-dependency-injectio... β†’ ) to change the priority if it works for you.

  • πŸ‡΅πŸ‡·Puerto Rico Jaime_Pomales

    Yes of course, that's always possible, but the problem is that this module breaks normal admin theme functionality of the civicrm module, which is used by thousands of sites.

    In my own case, modifying the priority did not affect my multiple domain setup negatively. All domain/themes were selected properly as expected, and the backend of civicrm stayed with its admin theme.

    CiviCRM a well supported module and has been around for decades at this point. When domain_theme_switch is enabled, it takes over the admin theme priority in situations where the admin theme previously worked as expected.

    I know it's a relatively small edge case, but I would suggest perhaps a less aggressive default theme priority as a way to make this module more useful out of the box when interacting with CiviCRM installs.

  • πŸ‡ΊπŸ‡¦Ukraine abramm Lutsk

    What's interesting is that the default theme negotiator in core has priority -100 so both 0 and 10 are fine with core.
    However, CiviCRM theme has its own negotiator with 0 priority:

    https://github.com/civicrm/civicrm-drupal/blob/8.x-5.2/modules/civicrmth...

    As you've suggested, changing domain_theme_switch's priority to 0 may work (or may not - depends on how specific Drupal version service collector handles ordering of tagged services with same priority).

    We could go a little bit further an change the priority to -1 but I've just looked quickly through one of my projects and found at least webform module which has zero priority theme negotiator and could be affected.

    Maybe a simple submodule (e.g. domain_theme_switch_civicrm or domain_theme_switch_priority) with service provider altering the priority would work? That should cover the case and would be backwards compatible.

  • πŸ‡΅πŸ‡·Puerto Rico Jaime_Pomales

    Thank you for looking into it as well! I appreciate that you are dedicated to doing things the right way. I'm in your debt.

    I think what you have suggested is the best solution to sort this out.

  • Status changed to Closed: works as designed about 1 year ago
  • πŸ‡ΊπŸ‡¦Ukraine abramm Lutsk

    You're welcome Jaime_Pomales, please reopen the issue and let me know if you'd want to contribute the MR with submodule changing the priority.
    I'm closing the ticket for now.

Production build 0.71.5 2024