You are here

function values_load in Values 7

Same name and namespace in other branches
  1. 6 values.module \values_load()

Loads values object from the database.

Parameters

$name: The name of the value set to load

$reset: Optional argument to force loading fresh from the db instead of from the cache. Defaults to FALSE

Return value

A value set object

4 calls to values_load()
values_form in ./values.module
Form for adding a new value set.
values_load_all in ./values.module
Loads all value sets.
values_load_options in ./values.module
Load a value set's values formatted as an options array
_values_name_exists in ./values.module
Render API callback: Checks if the value set machine name is taken.
1 string reference to 'values_load'
values_schema in ./values.install
Implements hook_schema().

File

./values.module, line 787
API for managing reusable value sets.

Code

function values_load($name, $reset = FALSE) {
  if (is_object($name)) {
    $name = $name->name;
  }
  if (module_exists('ctools')) {

    // Try using Chaos tools suite for exporting and caching
    ctools_include('export');
    $value_sets = ctools_export_load_object('values_sets', 'names', array(
      $name,
    ));
  }
  else {

    // In the absence of ctools, use our own basic static caching
    $value_sets =& drupal_static(__FUNCTION__, array(), $reset);
    if ($reset || !isset($value_sets[$name])) {
      $value_sets[$name] = db_query("SELECT * FROM {values_sets} WHERE name = :name", array(
        ':name' => $name,
      ))
        ->fetchObject();
      if (isset($value_sets[$name]->data)) {
        $value_sets[$name]->data = unserialize($value_sets[$name]->data);
      }
    }
  }
  if ($name && isset($value_sets[$name])) {
    if (!empty($value_sets[$name]->data)) {
      usort($value_sets[$name]->data, 'values_sort_by_weight');
    }
    return $value_sets[$name];
  }

  // @todo: What is this for? It was in the original d7 upgrade...
  // $node_additions = FALSE;
  // foreach ($node_additions as $property => &$value) {
  //   $name->$property = $value;
  // }
}