function themekey_rule_set in ThemeKey 7
Same name and namespace in other branches
- 6.4 themekey_build.inc \themekey_rule_set()
- 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.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
5 calls to themekey_rule_set()
- ThemekeyMultipleNodePropertiesTestCase::testMultipleProperties in tests/
ThemekeyMultipleNodePropertiesTestCase.test - 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 332 - 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'])) {
// TRANSACTIONS - SEE http://drupal.org/node/355875
// The transaction opens here.
$txn = db_transaction();
// new entry should be added at the end of the chain
$result = db_select('themekey_properties', 'tp');
$result
->addExpression('MAX(weight)', 'weight');
$weight = $result
->execute()
->fetchField();
// 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());
}
else {
drupal_write_record('themekey_properties', $item, 'id');
}
// $txn goes out of scope here, and the entire transaction commits.
}