2

Anyone know if it is possible to have Drupal modules enabled/active only when a current theme is present?

Working on a feature where I only need one module to be enabled when the site is accessed via a specific theme controlled by the ThemeKey module in Drupal 7.

  • 1
    Maybe you can disable not the module, but the effects of that module (the basic example is disabling a block in a specific theme). What are the effects that you want to disable? – Marco Panichi Dec 27 '12 at 20:54
  • In short I just need to make sure that for a specific theme of mine not to execute the actions of the Front Page Module which redirects a user to a different URL. The idea is for my mobile theme where it is a shell site with links to an iframe. Example is here via iOS where the content is actually just a bare-bone theme fed through and iFrame. Viewable only on iOS. – user12342 Dec 27 '12 at 20:59
  • (Context mobile detect)[drupal.org/project/context_mobile_detect] is a lightweight module that detect if user is using a mobile browser. Could be useful? – Marco Panichi Dec 27 '12 at 21:18
  • It works for blocks and such but nothing in regards to disabling modules. But we may be going in the right direction. Perhaps there is some PHP code we can add on to showcase modules as a selectable option. – user12342 Dec 27 '12 at 22:31
1

Themes are enabled/disabled in Drupal by altering the flag in the database table system. And these settings are common for all the users irrespective of which device/ how they are accessing your page.

So in your case it is about making sure that only the files from necessary modules are loaded based on the current theme.

You can use $theme global variable to find out the current theme, and then based on that you can fetch the files from the necessary modules only. You can check the code from js module how the second part can be implemented. You need to have patience though ;)

| improve this answer | |
1

It might be possible, with some hacks, but definitely is not built in and nothing I would encourage. Modules configuration is global. Enabling and disabling them is often slow, as no one bothers to optimize something that is meant to occur once in the lifetime anyway. So allowing this would kill your performance.

Second problem is cache. Proxies can, and often will serve responses from cache, even redirections. So your site might not be able to even know what type of browser accessed it. It might be unable to even notice it is accessed.

Last but not least, if search engine robot detects you serve it different content than you serve to it's clients, your position in result will go down the drain. They are pretty good at detecting changes in theming, but different module sets are only needed if you want to generate actual content differently, or to decide if to perform redirection. Both actions are no-go for SEO purposes.

TL;DR : Probably possible. Don't do it.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.