Any comments regarding default variable namespaces? <br>Right now I have a lot of long variable names just to avoid clashes with my own stuff.<br><br>variable_get('my_module_name_my_variable_name_var', MY_DEFAULT_VALUE);
<br><br>I was wondering if we should have variables within their own module namespaces.<br>Sort of like local module variables (stored in the db of course) that would be guarrenteed<br>unique???<br><br>Also, a side benefit of namespaces might be something like this:
<br><br>$vars = variable_get_array('my_module_name');<br><br>which could load all the variables for a module with one db call.<br><br><br><br><div><span class="gmail_quote">On 5/3/07, <b class="gmail_sendername">Earnie Boyd
</b> <<a href="mailto:earnie@users.sourceforge.net">earnie@users.sourceforge.net</a>> wrote:</span><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
Quoting Gabor Hojtsy <<a href="mailto:gabor@hojtsy.hu">gabor@hojtsy.hu</a>>:<br><br>> Hi,<br>><br>> To be able to translate variables to multiple languages in Drupal<br>> nicely, we would need a small conceptual change, which would benefit
<br>> all of the Drupal developers, so I am posting the call here in hopes<br>> we have someone or a small group to pick this task up.<br>><br>> **We need a central place to define variable defaults**<br>><br>
<br>At the top of the module:<br><br><?php<br>define('MY_DEFAULT_VALUE', t('my_default_value'));<br>?><br><br>> Simple! Now whenever you need a variable, you do<br>><br>> variable_get('my_fine_var', 'my_default_value');
<br>><br><br>Then in the code:<br><br><?php<br>variable_get ('my_find_var', MY_DEFAULT_VALUE);<br>?><br><br>> The problem with this is that you need to repeat this multiple times,<br>> and of course there is a chance you need to modify it later on, so
<br>> you need to find all places a variable is used. Not good. Remember<br>> the changes from bluemarine to garland, we have been fixing<br>> theme_default errors for days, finding out places where the variable<br>
> was used...<br>><br><br>I then only have one place to edit.<br><br>> So we need a central place to define variable defaults. For Drupal 6<br>> this is enough now:<br>><br><br>The central place is at the top of the module with a define statement.
<br><br>> hook_settings() {<br>> return array(<br>> 'my_fine_var' => 'my_default_value',<br>> );<br>> }<br>><br>> Have fun with naming it hook_settings(), as far as I see, it is an
<br>> appropriate name, and not taken at the moment :) So Drupal can do a<br>> module_invoke_all() on hook_settings() and collect defaults to all<br>> variables from the modules defining them. It gets easier and shorter
<br>> to use variables:<br>><br>> variable_get('my_fine_var');<br>><br><br>variable_get('my_fine_var', MY_DEFAULT_VALUE) is simple enough. I<br>don't understand why we would need to add this complication and
<br>overhead.<br><br>Earnie<br></blockquote></div><br><br clear="all"><br>-- <br>-> JV