When I migrate code and settings from staging to production, I need a way to migrate themekey properties/rules. Is there a function that I can use to do this? I would put my code in a hook_update function, or I would put it in a standalone script to be executed via 'drush php-script'.

I don't see an import/export function, so calling a function seems like the only route.

Thanks,
Cliff

Comments

mkalkbrenner’s picture

You can use ThemeKey's (experimental) support of https://drupal.org/project/features

meecect’s picture

yes, I was just browsing the code and saw the feature support right after posting. However, I'm loath to install features just to get this. It would require a complete change in our development workflow, and more modules to install and test. Isn't there any function like themekey_rule_save(&$rule_array) or something?

I was looking in the database, and it seems like the data structure is quite simple:

nid property operator value weight theme enabled wildcards parent module
1 taxonomy:tid_and_childs = 87 1 pokemon_xy 1 a:0:{} 0 themekey

I'm tempted to just use db_query and insert my row, ut I'd like to use a function that might give other modules an opportunity to fire their hooks. All of my entries will be basically the same as the above sample, but with just different values and theme contents.

Thanks for the quick response,
Cliff

meecect’s picture

maybe themekey_rule_set() ?

mkalkbrenner’s picture

Yes, the API you're looking for is located in themekey_build.inc.
https://drupal.org/project/mobile_tools 7.x-3.x is using it.

mkalkbrenner’s picture

BTW the features export stuff creates nothing else than php code that could be evaluated to import ThemeKey rules.
Maybe you can simply trigger that code manually without features ;-)
This code uses ThemeKey's API.

meecect’s picture

thanks, themekey_rule_set works fine.

mkalkbrenner’s picture

Status: Active » Closed (fixed)
couloir007’s picture

I want to create and enable a rule with drush, the code I use below works as long as I don't set the enabled variable.

  module_load_include('inc', 'themekey');
  $item = array();

  $item['property'] = 'node:type';
  $item['value'] = 'node_type';
  $item['theme'] = 'theme_name';
  $item['enabled'] = 1;

  themekey_rule_set($item, 'themekey');

If I don't set enabled, it creates it disabled, if I do I get:

Drush command terminated abnormally due to an unrecoverable error. [error]
Error: Call to undefined function themekey_rule_set() in...

Any insight would be great.

Thank you.

nmillin’s picture

@couloir007's code works great with hook_update_N(), but I needed to update

module_load_include('inc', 'themekey');

to

module_load_include('inc', 'themekey', 'themekey_build');

Just adding a note in case someone else tries to do this. Thanks!