You are here

function token_var_tokens in Token Variable 7

Same name and namespace in other branches
  1. 8 token_var.module \token_var_tokens()

Implements hook_tokens().

File

./token_var.module, line 56

Code

function token_var_tokens($type, $tokens, array $data = array(), array $options = array()) {
  $replacement = array();
  if ($type == 'variables') {
    foreach ($tokens as $name => $original) {
      $replacement[$original] = variable_get($name, '');
    }
  }
  elseif ($type == 'variables_array') {
    foreach ($tokens as $name => $original) {
      $key = substr($name, 0, strpos($name, '|'));
      $index = substr($name, strpos($name, '|') + 1);
      $replacement_array = variable_get($key, '');
      if (is_array($replacement_array)) {
        $replacement[$original] = $replacement_array[$index];
      }
      else {
        $replacement[$original] = '';
      }
    }
  }
  return $replacement;
}