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

Gabor Hojtsy gabor at hojtsy.hu
Thu May 3 14:23:15 UTC 2007


Earnie Boyd wrote:
>> **We need a central place to define variable defaults**
> 
> At the top of the module:
> 
> <?php
> define('MY_DEFAULT_VALUE', t('my_default_value'));
> ?>
> 
> Then in the code:
> 
> <?php
> variable_get ('my_find_var', MY_DEFAULT_VALUE);
> ?>
> 
> I then only have one place to edit.
> The central place is at the top of the module with a define statement.
> 
>>   hook_settings() {
>>     return array(
>>       'my_fine_var' => 'my_default_value',
>>     );
>>   }
> 
> variable_get('my_fine_var', MY_DEFAULT_VALUE) is simple enough.  I don't 
> understand why we would need to add this complication and overhead.

Ernie, I am fine with this solution too for Drupal itself.

BUT locale module will require a list of variables and their default 
values defined somewhere, so we will need to do that ourselfs in this 
case. It seemed to be odd to do this as part of the hook_locale() 
introduced today, but if hook_settings() seems to be overcomplication, 
then we need to go that way. I thought that if

  - we can save extra typing and value passing on variable_get calls
  - we have a hook to reuse when we need a list of variables
    to present for localization

adds pluses over just using constants.

Sure, only using constants for default variable values could be make 
variable usage better, but I think a hook do more just by being a 
central place and not a set of unrelated constants.

Gabor


More information about the development mailing list