public static function Vars::loadDefaults in Variable API 7
Same name and namespace in other branches
- 6.2 vars.module \Vars::loadDefaults()
- 6 vars.module \Vars::loadDefaults()
- 7.2 vars.classes.inc \Vars::loadDefaults()
Loads the default value for all the variables respecting some conditions.
This function is used to load the default value for all the variables respecting some conditions. The function should not be called from modules; it's thought to be used only from the Variable API module.
Parameters
$cid: The cache ID of the data to retrieve.
$conditions: A DatabaseCondition object for the conditions the persistent variables must respect.
Return value
An array containing information about the default value for the persistent variables.
See also
vars_node_type()
3 calls to Vars::loadDefaults()
- Vars::offsetGet in ./
vars.module - Implements ArrayAccess::offsetGet().
- VarsExtendedTestCase::testReadingVars in tests/
vars.test - vars_node_type_delete in ./
vars.module - Implements hook_node_type_delete().
File
- ./
vars.module, line 114 - Implement an API to handle persistent variables.
Class
- Vars
- @file Implement an API to handle persistent variables.
Code
public static function loadDefaults($cid, DatabaseCondition $conditions = NULL) {
if ($cache = cache_get($cid, 'cache_vars')) {
return $cache->data;
}
if ($cid == 'node_type') {
$conditions = db_and()
->condition('vd.flags', Vars::VARS_NODE_TYPE);
}
$defaults = array();
$query = db_select('variable_default', 'vd')
->fields('vd', array(
'name',
'value',
'flags',
));
if (isset($conditions)) {
$query
->condition($conditions);
}
foreach ($query
->execute() as $var) {
$index = $var->flags ? 'dynamic' : 'static';
$defaults[$index][$var->name] = unserialize($var->value);
}
drupal_alter('vars_default_values', $defaults, $cid);
cache_set($cid, $defaults, 'cache_vars');
return $defaults;
}