Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ISiteThemeService GetSiteThemeAsync() returns the front-end theme on the Admin page #15150

Closed
Psichorex opened this issue Jan 23, 2024 · 10 comments

Comments

@Psichorex
Copy link
Contributor

Psichorex commented Jan 23, 2024

Describe the bug

Injecting ISiteThemeService siteThemeService or IThemeManager and calling either GetSiteThemeAsync or GetThemeAsync() will return the Front-end theme instead of the admin theme.

I want to determine inside of a Middlaware whether the Current Theme is using Lombiq.BaseTheme as its BaseTheme.
If yes I want to remove bootstrap resources.

The problem here is now that I can't determine if I am on the admin page because the above described services will not return TheAdminTheme but the frontend theme only.

So my problem is that I want to get the CurrentTheme that is now being displayed and if that is the TheAdminTheme I don't want to remove bootstrap as it will destroy the admin page.

To Reproduce

Steps to reproduce the behavior:

  1. Create something that will call either IThemeManager GetThemeAsync() or ISiteThemeService GetSiteThemeAsync()
  2. Navigate to the Admin page and place a breakpoint on the call
  3. Refresh the admin page to hit the breakpoint
  4. You should see in the IDE locals that the Theme returned is the Front-end theme in my case TheBlogTheme

Expected behavior

It should return TheAdminTheme

Screenshots

Screenshots are made from a fresh clone of the OrchardCMS repository so it is not my local project.
image
image

@hishamco
Copy link
Member

Please use IAdminThemeService instead

@Psichorex
Copy link
Contributor Author

Please use IAdminThemeService instead

I checked IAdminThemeService and I don't see a method in it for my usecase.
So sorry for the lack of information I am adding this part to the issue description:

I want to determine inside of a Middlaware whether the Current Theme is using Lombiq.BaseTheme as its BaseTheme.
If yes I want to remove bootstrap resources.

The problem here is now that I can't determine if I am on the admin page because the above described services will not return TheAdminTheme but the frontend theme only.

So my problem is that I want to get the CurrentTheme that is now being displayed and if that is the TheAdminTheme I don't want to remove bootstrap as it will destroy the admin page.

So after debugging into IAdminThemeService it will give me the IExtensionInfo but I don't see the way it could determine whether that is being actually displayed.

@hishamco
Copy link
Member

Use ISiteThemeService to check the site theme or IAdminThemeService if you want to check the current admin theme

@Piedone
Copy link
Member

Piedone commented Jan 24, 2024

ISiteThemeService is for the site, i.e. not admin, theme. However, IThemeManager.GetThemeAsync() should return the current theme regardless, i.e. the site theme (most possibly) on the frontend, and the admin theme on the dashboard. I just checked with the latest source and this is what happens too.

However, I believe we tried that during our debugging session @Psichorex and it also always returned the site theme, even when on the dashboard. Please check with the latest source though.

@Psichorex
Copy link
Contributor Author

Psichorex commented Jan 25, 2024

This is what happens when I am making a call with IThemeManager.GetThemeAsync() in the latest source:
Admin becomes totally unusable
image

If I remove the call admin becomes as usual again.

@Piedone
Copy link
Member

Piedone commented Jan 25, 2024

Please tell how it works for you as mentioned above.

@Psichorex
Copy link
Contributor Author

For me the 1.8.2 source does exactly this at the minute:
ISiteThemeService.GetSiteThemeAsync() returns the front-end theme always period.

IThemeManager.GetThemeAsync() currently breaks the admin page for me when it is called from the test middleware I created:
image
This code at the minute breaks the admin site as I attached a picture above.

Debugging this broken admin site the IThemeManager.GetThemeAsync() for me still returns the front-end theme and not the admin but this could be to the broken Admin UI but I doubt that.

@Psichorex
Copy link
Contributor Author

Yes I can now reassure that if I use IThemeManager.GetThemeAsync() anywere in the code in the latest source the following page pops up when I am trying to access the admin:
image

@ns8482e
Copy link
Contributor

ns8482e commented Jan 25, 2024

That's because middleware runs before filters.

Creating MVC action filter instead of middleware will solve your problem.

@Psichorex
Copy link
Contributor Author

As per @ns8482e said I couldn't use IThemeManager in a Middleware.
Also our problem rooted from OC moving out bootstrap from the TheAdmin.css we solved that locally.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants