You are here

function variables_execute in Patterns 7

Same name and namespace in other branches
  1. 7.2 patterns_components/components/system.inc \variables_execute()
1 string reference to 'variables_execute'
system_patterns_callbacks in patterns_components/components/system.inc

File

patterns_components/components/system.inc, line 450

Code

function variables_execute($action, &$data) {
  $names = array();
  for ($i = 0; $variable = $data[$i]; $i++) {
    if ($action === PATTERNS_DELETE) {
      variable_del($variable['name']);
    }
    else {
      $var = variable_get($variable['name'], NULL);
      if (is_array($var)) {

        // make sure we don't lose parts of the array that were not defined by pattern's action
        // TODO: is this a good practice?
        $var = array_merge($var, $variable['value']);
        variable_set($variable['name'], $var);
      }
      else {
        variable_set($variable['name'], $variable['value']);
      }
    }
    $names[] = $variable['name'];
  }
  $msg = t('Variable(s) %vars updated.', array(
    '%vars' => implode(', ', $names),
  ));
  return patterns_results(PATTERNS_SUCCESS, $msg);
}