You are here

function _locations_token_helper in Location 7.3

Callback function to handle getting the correct location token.

1 call to _locations_token_helper()
location_tokens in ./location.tokens.inc
Implements hook_tokens().

File

./location.tokens.inc, line 154
Make tokens about location available.

Code

function _locations_token_helper($locations, $location_key, $which = 0, array $options = array()) {
  $sanitize = !empty($options['sanitize']);

  // That location doesn't exist.
  if (!isset($locations[$which])) {
    return '';
  }

  // Load the country name and return it.
  if ($location_key == 'country_name') {
    if (!empty($locations[$which]['country'])) {
      $val = location_country_name($locations[$which]['country']);
      return $sanitize ? check_plain($val) : $val;
    }
    return '';
  }

  // Load the province name and return it.
  if ($location_key == 'province_name') {
    if (!empty($locations[$which]['country']) && !empty($locations[$which]['province'])) {
      $val = location_province_name($locations[$which]['country'], $locations[$which]['province']);
      return $sanitize ? check_plain($val) : $val;
    }
    return '';
  }

  // Handle all other values.
  if (!empty($locations[$which][$location_key])) {
    return $sanitize ? check_plain($locations[$which][$location_key]) : $locations[$which][$location_key];
  }
  return '';
}