You are here

public static function Vars::loadDefaults in Variable API 7.2

Same name and namespace in other branches
  1. 6.2 vars.module \Vars::loadDefaults()
  2. 6 vars.module \Vars::loadDefaults()
  3. 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 Variables 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()

2 calls to Vars::loadDefaults()
Vars::offsetGet in ./vars.classes.inc
Implements ArrayAccess::offsetGet().
vars_node_type_delete in ./vars.module
Implements hook_node_type_delete().

File

./vars.classes.inc, line 229
Classes implemented by the Variable API module.

Class

Vars
@file Classes implemented by the Variable API module.

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;
}