[development] low hanging fruit for Drupal 6: variable defaults

Gabor Hojtsy gabor at hojtsy.hu
Thu May 3 08:55:57 UTC 2007


Hi,

To be able to translate variables to multiple languages in Drupal 
nicely, we would need a small conceptual change, which would benefit all 
of the Drupal developers, so I am posting the call here in hopes we have 
someone or a small group to pick this task up.

**We need a central place to define variable defaults**

Simple! Now whenever you need a variable, you do

   variable_get('my_fine_var', 'my_default_value');

The problem with this is that you need to repeat this multiple times, 
and of course there is a chance you need to modify it later on, so you 
need to find all places a variable is used. Not good. Remember the 
changes from bluemarine to garland, we have been fixing theme_default 
errors for days, finding out places where the variable was used...

So we need a central place to define variable defaults. For Drupal 6 
this is enough now:

   hook_settings() {
     return array(
       'my_fine_var' => 'my_default_value',
     );
   }

Have fun with naming it hook_settings(), as far as I see, it is an 
appropriate name, and not taken at the moment :) So Drupal can do a 
module_invoke_all() on hook_settings() and collect defaults to all 
variables from the modules defining them. It gets easier and shorter to 
use variables:

   variable_get('my_fine_var');

We can either cache the default vars as returned by the callback in the 
variable_get() function, or in the database among other variables, you 
get the idea. It is important to have all variables defined in 
hook_settings(), even if the default value is an empty string or array.

Don't care yet about how this fits into translatable variables, because 
we can only follow up on that if this gets done. So someone please grab 
this issue and run with it ;)

Gabor


More information about the development mailing list