I have the problem since update from 7.x-3.4 to 7.x-3.5.

This happens on following domain configuration:
There are 3 domains, one marked as default domain. All 3 domains use a different sub-theme, all sub-themes use the same parent theme. There is an administration theme set on all 3 domains, all set on the same pages, and all use the same admin theme.

Scenario: As a guest (or a user without corresponding permissions) trying to access administration pages which use an admin theme, I get a 403 rendered with a wrong theme.
More specific: I access the default domain site, trying to load an administration page without required permissions. The 403 page should render with the theme set for the current site, because I have no right to use the admin theme. Instead, an other theme from an other, non-default domain is being loaded.

There is no other module installed which affects theme manipulation on this process.

With previous version 7.x-3.4 this worked fine.

Marked as major because wrong theme loading breaks site's consistency.

Comments

agentrickard’s picture

Right. So let me see if I have this correct.

* 3 domains. Each has a specific theme and specific admin theme.
* User tries to access /admin. Gets 403 page.
* 403 page renders in the admin theme of the current site.

Is that last part correct? Or does it render in the admin theme of the default site?

agentrickard’s picture

In my test. The 403 returned the theme for the default domain, even though I was on a different domain.

agentrickard’s picture

Here's the problem code, from domain_theme_custom_theme():

  // Check for a custom admin theme.
  if (isset($conf['admin_theme']) && path_is_admin(current_path())) {
    $theme = domain_theme_lookup($_domain['domain_id'], $conf['admin_theme']);
  }
  else {
    // Assign the theme selected, based on the active domain.
    $theme = domain_theme_lookup($_domain['domain_id']);
  }

Let's try reversing those lines.

agentrickard’s picture

Status: Active » Needs review
StatusFileSize
new993 bytes

This should work.

agentrickard’s picture

StatusFileSize
new983 bytes

The $_GET['q'] is not required.

Problem is, we've seen misbehavior using menu_get_item() here before, especially when AJAX is involved (as in Features admin).

mxh’s picture

Although you've already spotted the problem right, let me correct your assumption from #1:

* 3 domains. Each has a specific theme and the same admin theme set on the same pages.
* User tries to access /admin. Gets 403 page.
* 403 page renders in an non-admin theme which is not allocated to the current site. A wrong theme is being rendered on these pages.

Does menu_get_item() not work well with AJAX in general?

agentrickard’s picture

Right. As I understand it, the 403 should not render in the admin theme. It should render in the assigned domain theme.

The problem with AJAX and menu_get_item() is that the second page request (the AJAX call) can reset the menu item and throw off the expected behavior. I have seen that with Features and Display Suite admin pages.

If the Features admin works with this code, then it should be ready to go.

agentrickard’s picture

Status: Needs review » Needs work

So this causes Features to display in the wrong theme, due to the AJAX.

See #1718968: Domain Conf administrative theme <=> Domain Theme theme settings for where this code was introduced.
See #1419090: Domain theme, admin theme broken broken for certain paths in Features module for the Features issue.

mxh’s picture

Right. As I understand it, the 403 should not render in the admin theme. It should render in the assigned domain theme.

Yes.

This seems to become a difficult one. In my next free time, I will also look for a solution.

agentrickard’s picture

It is difficult, because of the execution order of the code and the frustrations of the menu system, we cannot check for menu access without invoking menu_get_item(), and invoking that function breaks certain admin paths.

I have not found a way to fix your issue without re-breaking #1419090: Domain theme, admin theme broken broken for certain paths in Features module or doing handstands to load the menu data without calling menu_get_item().

At this point in the call stack, even drupal_get_http_headers() returns empty, because headers haven't been set yet.

agentrickard’s picture

StatusFileSize
new1.07 KB

Step away for a bit, and clarity appears ;-).

This would, at least, work for anon users.

mxh’s picture

Yep, #11 works for me with anonymous users.

Now authenticated users without required permissions get the admin theme loaded, but they should get the same result as anonymous users.

I think the problem is now somewhere else, at a point where the admin theme is being set. Whatever I do in domain_theme_custom_theme(), even when I return a fixed string with a machine name of a theme, the admin theme is used when the user is authenticated.

agentrickard’s picture

I don't follow point 3 above.

The issue is that we can't run a check for menu item access without breaking certain theme functions. That's what the old Features issue is about. The patch in #11 tries to fix that, and is perhaps correct. If you can view admin theme and the 403 is an admin page, using the admin theme seems appropriate.

There is also a permission for 'view administration pages', and we could check that instead.

agentrickard’s picture

Status: Needs work » Reviewed & tested by the community

The patch mimics what core does. If you can access the admin theme in core, your 403 is delivered in the admin theme.

/**
 * Implements hook_custom_theme().
 */
function system_custom_theme() {
  if (user_access('view the administration theme') && path_is_admin(current_path())) {
    return variable_get('admin_theme');
  }
}
mxh’s picture

Ok I have tested with previous domain version 7.x-3.4 and it shows the same behavior now when #11 is used in 7.x-3.5, so for me this issue can be marked as fixed.

But I don't understand why an authenticated user without permission 'view the administration theme' can ever see a page rendered with admin theme, like at the moment 403 admin pages.

Anyway, thank you for the ultrafast support.

agentrickard’s picture

At the moment, it's because we don't check that access. This patch fixes that.

agentrickard’s picture

Status: Reviewed & tested by the community » Fixed

Committed!

   4ee008b..93e7b19  7.x-3.x -> 7.x-3.x

Status: Fixed » Closed (fixed)

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