You are here

Module variable

Submitted by Peter on Thu, 2011-11-17 08:50

The Module variable add-on module for Drupal provides a mechanism to use variable storage in a more modern, efficient, and module oriented approach than the current Drupal variable_get(), variable_set() system.

The module is built on code from several projects over the years, including a framework for Web sites I build many years before Drupal appeared. This version is reduced to the minimum code required to work as a Drupal add-on module.

The module could be open sourced and loaded on to drupal.org. If someone wants to learn drupal module development and contribute a to Drupal, I am happy to work with you and contribute the current code plus some extensions. This could be in Drupal 8 if implemented fast enough.

What does the current versions do? It works with the Drupal variable_get(), variable_set(), and variable_del() functions to store settings for modules. The difference is the settings are grouped by module. There is one database IO operation to load all the settings for one module.

Drupal core

The Drupal node code is about as core as you can get with Drupal. The node code uses three different ways to set four options. If it was converted to variable_module, the whole four options would be set one standard way and read with one database request instead of three. There are other examples and one is enough.

OOP

The code is object oriented so you can use an object instead of messy functions. You can start direct by creating the object from the class or you can use a Drupal style function to load the class and create the object. All getting, setting, and deleting of variables is performed through the object. All functions have a multiple option to to work with lists of variables.

The OOP approach is demonstrated in Module variable new. The Drupal style start module is demonstrated in Module variable start.

Download

You can access a Druplified version of the code at drupal.org/sandbox/peter/1372740. The code is uglier and harder to read because it is twisted into the messy Unix style format required for code stored on drupal.org. The one on drupal.org is the version matching this documentation.

Technology: