Hi, I've got a website with a regular and a mobile theme. The mobile theme is switched based on Mobile Tools and WURLF stuff.

So I can use the "Current theme" selection rule to show the fitting panel on the homepage.

This is what I do:
a) Variant 1 - selection rule - current theme - Deskop theme
b) Variant 2 - selection rule - current theme - Mobile theme

Expected result:
show correct variant for chosen theme, desktop/mobile

Actual result:
page not found on both homepages

After removing the selection rules, the homepage now shows Variant 1 on both themes.

Comments

Anonymous’s picture

P.S. Both variants "previews" show the correct stuff. Its just that the selection rules break page display. Of course they are valid themes, selected from the rule dropdown. If I try to create 2 panels and use the "access" rules, i get "access denied". Even though Im currently looking at the exact same theme that I used for the access rule.

freelylw’s picture

same problem here

codevoice’s picture

Subscribe, same problem here, same scenario.

merlinofchaos’s picture

Hmm. Perhaps the theme selection is happening after the variant selection process, so that at the time the tests are being run, no theme has actually been selected? What is selecting the theme?

merlinofchaos’s picture

Project: Panels » Chaos Tool Suite (ctools)
Version: 6.x-3.x-dev » 6.x-1.6
Status: Active » Fixed

No, testing this i see you're right; the access rule has absolutely no effect due to an error in the test. I checked in a fix. This is a CTools change, so moving to proper project.

jdidelet’s picture

+1 subscribing

shmelyonag’s picture

Not sure if this is a safe solution but:
1.Go to sites/all/modules/ctools/plugins/access/theme.inc
2.Look for this function ctools_theme_ctools_access_check() (near line 43 in 6.x-1.6)
3.It should look like this after correction:
function ctools_theme_ctools_access_check($conf, $context) {
// As far as I know there should always be a context at this point, but this
// is safe.
/*if (empty($context) || empty($context->data)) {
return FALSE;
}*/
return $conf['theme'] == variable_get('theme_default', 'yourtheme');
}
I've commented the if statement for $context. I don't know if this is safe but without that line and with correction from $GLOBALS['theme'] to variable_get('theme_default', 'yourtheme') everything works for me.
Hope this will help someone.
If you have better idea please share, please tell more about that $context variable, why it shouldn't be empty?
Thanks

merlinofchaos’s picture

If you'd look in the most recent CTools -dev you'd see that's basically the change that's checked in. Not sure why you're investigating something that's already fixed.

MartinSfromB’s picture

Version: 6.x-1.6 » 6.x-1.x-dev
Status: Fixed » Active

I have 2 variants of a page as frontpage. Both have an access check against the used theme (the main theme and my personal theme). This doesn't work. At the access check 'custom_theme' an 'theme' are empty, only 'theme_default' is filled. If i use an access check against the theme with a panel on this page, it works correctly. If I now load the page, theme-variable is empty at the first access check (page variant) and correctly filled at the second check (panel).
Is it possible that a change in module weights could fix that problem?

For me it works if i call if (empty($GLOBALS['theme'])) init_theme(); at beginning of ctools_theme_ctools_access_check($conf, $context) but i don't know possible problems with this hack.

merlinofchaos’s picture

#9: Ahh you have user themes enabled? I suppose that needs to be checked as well. It's hard for me to decipher where in the system you think the theme is currently set at the time the check is run, so I am not quite sure.

Changing module weights probably does not do anything.

  else {
    $theme = variable_get('theme_default', 'garland');
  }

That code should see the default theme and compare it.

MartinSfromB’s picture

Module weights doesn't help. I agrree.
All works as supposed if the check is called for a pane on a page. Its perfect, no need to change!
In your function the gloabal $theme variable is checked. And this is the right solution to get all changes to the default theme. If a user selects a special theme or a modules does - all works correct with this check against the global $theme.

The problem is, that the global $theme is set by drupals init_theme() and this is (in my case?) after the access check to select a page variant.

I work for some days now with expicitly calling init_theme and see no negative behavior. If I look in drupals theme.inc I can see that it will never run twice because itself checks against gloabal $theme.

We also can delete checks against default_theme or custom_theme because its also done in init_theme,

So the access check schould simply look like this:

function ctools_theme_ctools_access_check($conf, $context) {
  // because in - some cases - the access check runs before the theme is loaded, we have to check if the theme system is correctly initialised
  if (empty($GLOBALS['theme'])) init_theme();
  // check if the current theme is the same as the access rule needs
  return $conf['theme'] == $GLOBALS['theme'];
}

Any other opinion?

Regards, Martin

merlinofchaos’s picture

We absolutely positively should not init_theme() here. That's why our check defaults to the variable that contains the theme.

I did, however, add a check for $user->theme in case that's going to override the default theme. Perhaps that's what we're missing in your case.

/**
 * Check for access.
 */
function ctools_theme_ctools_access_check($conf, $context) {
  if (!empty($GLOBALS['theme'])) {
    $theme = $GLOBALS['theme'];
  }
  else if (!empty($GLOBALS['custom_theme'])) {
    $theme = $GLOBALS['custom_theme'];
  }
  else if (!empty($GLOBALS['user']->theme)) {
    $theme = $GLOBALS['user']->theme;
  }
  else {
    $theme = variable_get('theme_default', 'garland');
  }

  return $conf['theme'] == $theme;
}
merlinofchaos’s picture

Status: Active » Fixed

Status: Fixed » Closed (fixed)

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