This module extends the Drupal core variable API that handles persistent variables. It implements a class that:

Just took over the module. Will be making stable releases for Drupal 7 and will support Drupal 6 for major issues.

  • allows finding the directory where a library has been installed (branch 2.x for Drupal 6 and 7),
  • forces Drupal to re-build the menus (branch 2.x for Drupal 6 and 7),
  • allows obtaining the value of a persistent variable without passing the default value to each function call,
  • deletes multiple persistent variables,
  • and implements functions to centralize static PHP variables. The functions are a back port of drupal_static(), and drupal_static_reset() implemented in Drupal 7.

Installation notes

Install the module only if you are instructed to do so, or you are a developer and want to use the module.

If you are installing Variable API because it is a dependency of another module, you need to first install (and enable) Variable API, and then install (and enable) the other module. If the modules are enabled at the same time, you will get the error message class Vars not found. The same problem is actually present if you install a module that depends from the Variable API using Drush; in the moment I am writing this note, Drush will not download the Variable API module, with the consequence that you will get the error message class Vars not found.

How does the code change when a module uses Variable API?

A module that depends on Variable API needs to define a class that extends Vars, overwrite Vars::getDefaults(), and call the class during the installation, update, and when the module is being removed.

The code to access persistent variables (or set them) is equivalent to the following:

$vars = new ModuleNameVars();

if (!$vars['cache_files']) {
  $vars['cache_files'] = TRUE;
}

The module is also able to use the default value of variables that are defined from modules that don't use Variable API; in this case, the module which uses Variable API needs define the class derived from Vars as:

class ExampleVars extends Vars {
  public function __construct() {
   parent::__construct('example', array(
     'sysVars' => array(
       'variable_defined_from_a_core_module' => FALSE,
     )
   ));
  }

  public function getDefaults() {
    return array(
      'example_first' => array('value' => 100, 'flags' => VARS_DYNAMIC),
      'example_second' => array('value' => 200),
      'example_third' => array('value' => 300),
      'example_fourth' => array('value' => array(400)),
      'example_fifth' => array('value' => array('abcdefghil')),
    );
  }
}

Version notes

  • Branch 2.x of the module defines the default value for the Drupal variables initialized by Drupal during the bootstrap.
  • In the Drupal 7 branch, the static methods Vars::staticValue(), and Vars::staticReset() are present for compatibility with the Drupal 6 branch of the module; the code using this module should be changed to directly use the Drupal 7 functions drupal_static(), and drupal_static_reset().

  • Updating from a different release of the development snapshot is not supported. To install a newer development snapshot, you always need to uninstall the previous version before copying the new one.
  • Development snapshots are intended for testing only. Don't use them in a production site, or for other purposes. If used in a production site, or for other purposes, there will be no support for any resulting problems.
Supporting organizations: 
Supports.

Project information

Releases