You are here

variable.tokens.inc in Variable 6

Same filename and directory in other branches
  1. 7.2 variable.tokens.inc
  2. 7 variable.tokens.inc

Builds placeholder replacement tokens system-wide data.

This file handles tokens for the global 'variable' token type.

File

variable.tokens.inc
View source
<?php

/**
 * @file
 * Builds placeholder replacement tokens system-wide data.
 *
 * This file handles tokens for the global 'variable' token type.
 */

/**
 * Implements hook_token_info().
 */
function variable_token_info() {
  $types['variable'] = array(
    'name' => t("Variables"),
    'description' => t("Tokens for variable values."),
  );
  $variable = array();
  foreach (variable_info() as $name => $info) {
    if (!empty($info['token'])) {
      $variable[$name] = array(
        'name' => $info['title'],
        'description' => !empty($info['description']) ? $info['description'] : t('Value of variable !name', array(
          '!name' => $info['title'],
        )),
      );
    }
  }
  return array(
    'types' => $types,
    'tokens' => array(
      'variable' => $variable,
    ),
  );
}

/**
 * Implements hook_tokens().
 */
function variable_tokens($type, $tokens, array $data = array(), array $options = array()) {
  $replacements = array();
  if ($type == 'variable') {
    foreach ($tokens as $name => $original) {
      $variable = variable_info($name, $options);
      if ($variable && !empty($variable['token'])) {
        $replacements[$original] = variable_format_value($variable, $options);
      }
    }
  }
  return $replacements;
}

Functions

Namesort descending Description
variable_tokens Implements hook_tokens().
variable_token_info Implements hook_token_info().