function themekey_rule_set in ThemeKey 6.4
Same name and namespace in other branches
- 6.2 themekey_build.inc \themekey_rule_set()
- 6.3 themekey_build.inc \themekey_rule_set()
- 7.3 themekey_build.inc \themekey_rule_set()
- 7 themekey_build.inc \themekey_rule_set()
- 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
4 calls to themekey_rule_set()
- themekey_features_save_rule_childs in ./
themekey_features.module - Takes a serialized ThemeKey Rule Chain as created by themekey_features_load_rule_childs() and replaces the current one in the database eith it.
- 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 can 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 323 - 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');
}
}