You are here

function countries_tokens in Countries 8

Same name and namespace in other branches
  1. 7.2 countries.tokens.inc \countries_tokens()
  2. 7 countries.tokens.inc \countries_tokens()

Implements hook_tokens().

File

./countries.tokens.inc, line 70
Builds placeholder replacement tokens for country-related data.

Code

function countries_tokens($type, $tokens, array $data = array(), array $options = array()) {
  $sanitize = !empty($options['sanitize']);
  $replacements = array();
  if ($type == 'country' && !empty($data['country'])) {
    $country = $data['country'];
    foreach ($tokens as $name => $original) {
      $replacements[$original] = country_property($country, str_replace('-', '_', $name), '', $sanitize);
    }
  }
  if ($type == 'default-country') {
    $country = country_load(variable_get('site_default_country', ''));
    $replacements += token_generate('country', $tokens, array(
      'country' => $country,
    ), $options);
  }
  return $replacements;
}