I need a Drupal 7 module that would allow anonymous users to switch theme by entering specific URI query string. For example:
- www.mysite.com/&q=garland would switch to Garland
- www.mysite.com/&q=seven would switch to Seven

Could you point me a built-in Drupal functions that could be used when writing such module? I need at least:
- a function to retrive query string for currently rendered page ($_GET['q'], right?)
- a function that would append a specific query string to all links on currently rendered page
- a function that would switch theme for currently rendered page

Thanks!

Comments

mdixoncm’s picture

It's probably worth taking a look at the switchtheme module - http://drupal.org/project/switchtheme - it might not do exactly what you want, but the code should give you some pointers on how to do what you are after ...

jarek foksa’s picture

Yeah, there is also ThemeKey module, unfortunately both of them are not compatible with Drupal 7.

jarek foksa’s picture

Here is my progress. I discovered hook_custom_theme() function. I called my module "switcher", I enabled Garland theme (though it's not the default theme) and I have placed following code in switcher.module file:

drupal_set_message("TEST", $type = 'status');

/**
* Implements hook_custom_theme().
*/
function switcher_custom_theme() {
  return 'garland';
}

I expected it to switch the current theme to Garland, but it does not seem to work. When I refresh the site the theme does not get switched. But I can see the "TEST" status message, so the module must have been installed correctly.

jarek foksa’s picture

It works! I just had to clear the cache.

jarek foksa’s picture

Now I just have to append a query string to all links.

Example: If user entered the page by clicking on "mysite.com/node/1?theme=garland" link, then all links on this page should have "?theme=garland" query string appended.

Any ideas how to do this?

ar-jan’s picture

Interesting, have you found a way to do this?

jarek foksa’s picture

Yeah, but I coudn't figure out how to do this with PHP so I used JavaScript. You can download the module from here. The implementation is not very elegant, but it works:
- http://demo.kiwi-themes.com/drupal-dev/?theme=garland
- http://demo.kiwi-themes.com/drupal-dev/?theme=tarski
- http://demo.kiwi-themes.com/drupal-dev/?theme=titan

jarek foksa’s picture

BTW, Drupal 7 version of the ThemeKey module is now available.