Community

Want to set default blocks when switching default themes [SOLVED]

So I have a couple of themes available on my sites for users to choose from. The regions don't match exactly, but I do want the blocks to appear in both templates. How do I set the default location for a given block when a theme is set as default? I want something like hook_template_default, but that of course does not exist.

EG, say I have a contact Information block. In theme1, I want it to appear in the "sidebar" region. In theme2 I want it to appear in the footer region. I don't want to have to go to blocks and manually reset this every time I switch themes. Is there a hook or other way I can accomplish this?

Comments

A suggestion

Hello,
This question might get better answers in the "Theme Development" forum :) https://drupal.org/forum/3

However, here is what I would look at. system_theme_default() http://api.drupal.org/api/drupal/modules!system!system.admin.inc/function/system_theme_default/7 does the following:   variable_set('theme_default', $theme);. Thus, you can use the opposite variable_get() later to compare a theme with the defailt.

Next, note the system_theme_default calls theme_enable() http://api.drupal.org/api/drupal/includes!theme.inc/function/theme_enable/7. Theme enable triggers the hook "hook_themes_enabled" (see module_invoke_all('themes_enabled', $theme_list);

Thus, it seems if you implement hook_themes_enabled http://api.drupal.org/api/drupal/modules!system!theme.api.php/function/hook_themes_enabled/7, that should get you started :)

Please note! If this solves your issue, please edit the subject line of your original post and add "[SOLVED]". That way, other folks can find the solution:)

Thinking is the best way to travel.

Thanks! Not exactly what I

Thanks! Not exactly what I was looking for but ended up working well enough. Basically I created a "system settings" form (custom one for the site administrators). They choose the theme from a list of themes. When they pick a theme, I enable that theme and disable the other themes doing a theme_disable, and then enable and set as default the new theme.

By doing it this way I can take advantage of the hooks_themes_enabled module (otherwise i could have both themes enabled at the same time and no way to hook into when they change).

You are welcome

Hello,
Great work!! Glad to have helped :)

There is always more than one way the "get it done" :) You could post a follow up in the "Theme Development:" forum. Someone developing a "theme" might have an alternative solution.

Again, great to see you got it working :)

Thinking is the best way to travel.