You are here

function themekey_rule_set in ThemeKey 6.2

Same name and namespace in other branches
  1. 6.4 themekey_build.inc \themekey_rule_set()
  2. 6.3 themekey_build.inc \themekey_rule_set()
  3. 7.3 themekey_build.inc \themekey_rule_set()
  4. 7 themekey_build.inc \themekey_rule_set()
  5. 7.2 themekey_build.inc \themekey_rule_set()

Stores ThemeKey rules in database. It creates a new dataset or updates an existing one.

Parameters

$item: reference to an associative array containing a ThemeKey rule structure:

  • id
  • property
  • operator
  • value
  • weight
  • theme
  • enabled
  • wildcards
  • parent
3 calls to themekey_rule_set()
themekey_rule_chain_form_submit in ./themekey_admin.inc
Form submission handler for themekey_rule_chain_form().
themekey_ui_set_path_theme in ./themekey_ui_helper.inc
Saves a theme assigned to a path alias as ThemeKey rule
themekey_update_static_rule in ./themekey_build.inc
Adds or modifies a so called static rule in the database. Static rules could be moved around in the chain and enabled or disabled by the site administrator but the values are immutable. There's one static rule per static property.

File

./themekey_build.inc, line 324
The functions in this file are the back end of ThemeKey which should be used only if you configure something but not when ThemeKey switches themes.

Code

function themekey_rule_set(&$item) {
  if ('drupal:path' == $item['property']) {
    list($item['value'], $item['wildcards']) = themekey_prepare_custom_path($item['value']);
  }
  else {
    $item['wildcards'] = array();
  }
  if (empty($item['id'])) {

    // prevent table lock issues with drupal_write_record
    // see http://drupal.org/node/372308#comment-2442664
    drupal_get_schema(FALSE);
    db_lock_table('themekey_properties');

    // new entry should be added at the end of the chain
    $weight = db_result(db_query("SELECT MAX(weight) FROM {themekey_properties}"));

    // if query fails $weight will be FALSE which will cause $item['weight'] to be set to '1'
    $item['weight'] = 1 + $weight;
    drupal_write_record('themekey_properties', $item, array());
    db_unlock_tables();
  }
  else {
    drupal_write_record('themekey_properties', $item, 'id');
  }
}