location.token.inc 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. <?php
  2. /**
  3. * @file
  4. * Short description.
  5. */
  6. /**
  7. * Implementation of hook_token_values().
  8. */
  9. function _location_token_values($type, $object = NULL) {
  10. if ($type == 'node' || $type == 'user') {
  11. if (!empty($object->locations)) {
  12. // @@@ Strip virtual fields?
  13. foreach ($object->locations as $key => $location) {
  14. // Normally, location_load_location() will take care of this.
  15. // However, token is commonly used during *saving*.
  16. // See #322328.
  17. if (empty($location['country_name'])) {
  18. if (!empty($location['country'])) {
  19. $location['country_name'] = location_country_name($location['country']);
  20. if (!empty($location['province'])) {
  21. $location['province_name'] = location_province_name($location['country'], $location['province']);
  22. }
  23. }
  24. }
  25. foreach ($location as $field => $value) {
  26. if (!is_array($value)) {
  27. $values["location-{$field}_{$key}"] = check_plain($value);
  28. }
  29. }
  30. // Backwards compatibility.
  31. $values["location-provincename_$key"] = $values["location-province_name_$key"];
  32. $values["location-countryname_$key"] = $values["location-country_name_$key"];
  33. }
  34. return $values;
  35. }
  36. }
  37. }
  38. /**
  39. * Implementation of hook_token_list().
  40. */
  41. function _location_token_list($type = 'all') {
  42. if ($type == 'node' || $type == 'user' || $type == 'all') {
  43. $tokens['location']['location-name_N'] = t('Location Name (If there are multiple locations per node, N is the iteration, starting with 0)');
  44. $tokens['location']['location-street_N'] = t('Street (If there are multiple locations per node, N is the iteration, starting with 0)');
  45. $tokens['location']['location-additional_N'] = t('Additional (If there are multiple locations per node, N is the iteration, starting with 0)');
  46. $tokens['location']['location-city_N'] = t('City (If there are multiple locations per node, N is the iteration, starting with 0)');
  47. $tokens['location']['location-province_N'] = t('State/Province (If there are multiple locations per node, N is the iteration, starting with 0)');
  48. $tokens['location']['location-province_name_N'] = t('State/Province Name (If there are multiple locations per node, N is the iteration, starting with 0)');
  49. $tokens['location']['location-postal_code_N'] = t('Postal Code (If there are multiple locations per node, N is the iteration, starting with 0)');
  50. $tokens['location']['location-latitude_N'] = t('Latitude (If there are multiple locations per node, N is the iteration, starting with 0)');
  51. $tokens['location']['location-longitude_N'] = t('Longitude (If there are multiple locations per node, N is the iteration, starting with 0)');
  52. $tokens['location']['location-country_N'] = t('Country (If there are multiple locations per node, N is the iteration, starting with 0)');
  53. $tokens['location']['location-country_name_N'] = t('Country Name (If there are multiple locations per node, N is the iteration, starting with 0)');
  54. return $tokens;
  55. }
  56. }