You are here

function currency_tokens in Currency 7.2

Same name and namespace in other branches
  1. 8.3 currency.tokens.inc \currency_tokens()

Implements hook_tokens().

File

currency/currency.tokens.inc, line 55
Contains Token API hook implementations.

Code

function currency_tokens($type, array $tokens, array $data = array(), array $options = array()) {
  $replacements = array();
  if ($type == 'currency' && isset($data['currency'])) {
    $currency_code = $data['currency'];
    if (isset($tokens['code'])) {
      $replacements[$tokens['code']] = $data['currency'];
      unset($tokens['code']);
    }
    if ($tokens) {
      ctools_include('export');
      $currency = currency_load($data['currency']);
      $map = array(
        'number' => 'ISO4217Number',
        'subunits' => 'subunits',
        'sign' => 'sign',
        'title' => 'title',
      );
      foreach ($tokens as $token => $original) {
        if (isset($map[$token])) {
          $replacements[$original] = $currency->{$map[$token]};
        }
      }
    }
  }
  return $replacements;
}