public static function Vars::loadDefaults in Variable API 6
Same name and namespace in other branches
- 6.2 vars.module \Vars::loadDefaults()
- 7.2 vars.classes.inc \Vars::loadDefaults()
- 7 vars.module \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: An array of conditions the persistent variables must respect.
$args: An array of arguments for the passed conditions.
Return value
An array containing information about the default value for the persistent variables.
See also
3 calls to Vars::loadDefaults()
- Vars::offsetGet in ./
vars.module - Implements ArrayAccess::offsetGet().
- VarsExtendedTestCase::testReadingVars in tests/
vars.test - vars_node_type in ./
vars.module - Implements hook_node_type().
File
- ./
vars.module, line 113 - Implement an API to handle persistent variables.
Class
- Vars
- @file Implement an API to handle persistent variables.
Code
public static function loadDefaults($cid, $conditions, $args) {
if ($cache = cache_get($cid, 'cache_vars')) {
return $cache->data;
}
if (!is_array($conditions)) {
$conditions = array(
$conditions,
);
}
if (!is_array($args)) {
$args = array(
$args,
);
}
$conditions = implode(' AND ', $conditions);
$defaults = array();
$result = db_query("SELECT * FROM {variable_default} WHERE " . $conditions, $args);
while ($var = db_fetch_object($result)) {
$index = $var->flags ? 'dynamic' : 'static';
$defaults[$index][$var->name] = unserialize($var->value);
}
if ($cid != 'node_type') {
drupal_alter('vars_default_values', $defaults, $cid);
}
cache_set($cid, $defaults, 'cache_vars');
return $defaults;
}