[development] low hanging fruit for Drupal 6: variable defaults
Gabor Hojtsy
gabor at hojtsy.hu
Thu May 3 21:30:20 UTC 2007
Dries Buytaert wrote:
> On 03 May 2007, at 21:43, Peter Wolanin wrote:
>> I don't think the suggestion below makes sense (setting variable
>> defaults via hook_install), at least if we assume that the way to
>> reset a module setting is to delete the corresponding variable.
>
> Setting a variable on hook_install sounds clumsy, especially when we
> have /dynamic/ variables of the form:
>
> variable_get($node->type ."_something", ...)
>
> You simply don't know at install time, what variables might become
> available later on ...
OK, then your constants tip (quoted below) does not stand, because
/dynamic/ named variables will not be able to have defaults. (Unless you
have a place to run define()-s with dynamic constant names, which would
be a hook run on the beginning of all page views or something, which
sounds quite scary).
So seems like /dynamic/ named variables rule out .install time variable
saving into the database and rule out constants, what do we get to? A
hook to retrieve variable defaults from? (evil grin)
> How about this:
>
> define('site_name', 'example');
>
> function variable_get($name) {
> $value = db_result(db_query(...));
> return $value ? $value : constant($name);
> }
>
> print variable_get('site_name');
>
> Might get us the best of both worlds? :)
Gabor
More information about the development
mailing list