variable.tokens.inc 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. <?php
  2. /**
  3. * @file
  4. * Builds placeholder replacement tokens system-wide data.
  5. *
  6. * This file handles tokens for the global 'variable' token type.
  7. */
  8. /**
  9. * Implements hook_token_info().
  10. */
  11. function variable_token_info() {
  12. $types['variable'] = array(
  13. 'name' => t("Variables"),
  14. 'description' => t("Tokens for variable values."),
  15. );
  16. $variable = array();
  17. foreach (variable_get_info() as $name => $info) {
  18. if (!empty($info['token'])) {
  19. $variable[$name] = array(
  20. 'name' => $info['title'],
  21. 'description' => !empty($info['description']) ? $info['description'] : t('Value of variable !name', array('!name' => $info['title'])),
  22. );
  23. }
  24. }
  25. return array(
  26. 'types' => $types,
  27. 'tokens' => array(
  28. 'variable' => $variable,
  29. ),
  30. );
  31. }
  32. /**
  33. * Implements hook_tokens().
  34. */
  35. function variable_tokens($type, $tokens, array $data = array(), array $options = array()) {
  36. $replacements = array();
  37. if ($type == 'variable') {
  38. foreach ($tokens as $name => $original) {
  39. $variable = variable_get_info($name, $options);
  40. if ($variable && !empty($variable['token'])) {
  41. $replacements[$original] = variable_format_value($variable, $options);
  42. }
  43. }
  44. }
  45. return $replacements;
  46. }