Hi there!
Thanks so much for writing this, this is one of those modules that I've wished I would just make the time to write, but never seem to be able to carve out time to do it. So thank YOU for taking the time to do it! :D

So, I think it would be helpful if you could specify to have it just output an array of variables and their settings instead of a variable_set call on each one. Even better would be if you could specify the module name and hook name for the variables. This would be very helpful in working with modules such as strongarm, where you are implementing a hook that returns an array of variables and their settings.

The nice thing about doing this, even if you aren't using strongarm, is that you can call the function on hook_enable & hook_disable like this (very helpful for features):

<?php
/**
 * Implementation of hook_enable().
 */
function example_enable() {
  foreach (_example_vars() as $key => $data) {
    variable_set($key, $data);
  }
}

/**
 * Implementation of hook_enable().
 */
function example_disable() {
  // Clean up variable settings.
  foreach (array_keys(_example_vars()) as $key) {
    variable_del($key);
  }
}
?>

I may have some time to work on a patch for this if you'd be open to this sort of functionality.

Comments

q0rban’s picture

Thought I'd document this, in case someone finds it useful. I guess you could simplify the above code even more if you wanted to:

<?php
  // hook_enable code.
  $vars = _example_vars();
  array_map('variable_set', array_keys($vars), $vars);

  // hook_disable code.
  array_map('variable_del', array_keys(_example_vars()));
?>
q0rban’s picture

Assigned: Unassigned » q0rban
Status: Active » Needs review
StatusFileSize
new4.59 KB

Here's a stab at it.

q0rban’s picture

StatusFileSize
new4.59 KB

minor fix.. Re-ordering the functions.

nancydru’s picture

I'd love to see this feature included.

q0rban’s picture

StatusFileSize
new4.59 KB

Re-rolling patch, as the previous one failed for me.

q0rban’s picture

StatusFileSize
new4.46 KB

Um.. I accidentally attached the same file. Let me try that again. :/

q0rban’s picture

StatusFileSize
new4.47 KB

A few fixes.

karens’s picture

Status: Needs review » Fixed

Looks useful, committed. Thanks!

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.