location.token.inc 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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(
  44. 'Location Name (If there are multiple locations per node, N is the iteration, starting with 0)'
  45. );
  46. $tokens['location']['location-street_N'] = t(
  47. 'Street (If there are multiple locations per node, N is the iteration, starting with 0)'
  48. );
  49. $tokens['location']['location-additional_N'] = t(
  50. 'Additional (If there are multiple locations per node, N is the iteration, starting with 0)'
  51. );
  52. $tokens['location']['location-city_N'] = t(
  53. 'City (If there are multiple locations per node, N is the iteration, starting with 0)'
  54. );
  55. $tokens['location']['location-province_N'] = t(
  56. 'State/Province (If there are multiple locations per node, N is the iteration, starting with 0)'
  57. );
  58. $tokens['location']['location-province_name_N'] = t(
  59. 'State/Province Name (If there are multiple locations per node, N is the iteration, starting with 0)'
  60. );
  61. $tokens['location']['location-postal_code_N'] = t(
  62. 'Postal Code (If there are multiple locations per node, N is the iteration, starting with 0)'
  63. );
  64. $tokens['location']['location-latitude_N'] = t(
  65. 'Latitude (If there are multiple locations per node, N is the iteration, starting with 0)'
  66. );
  67. $tokens['location']['location-longitude_N'] = t(
  68. 'Longitude (If there are multiple locations per node, N is the iteration, starting with 0)'
  69. );
  70. $tokens['location']['location-country_N'] = t(
  71. 'Country (If there are multiple locations per node, N is the iteration, starting with 0)'
  72. );
  73. $tokens['location']['location-country_name_N'] = t(
  74. 'Country Name (If there are multiple locations per node, N is the iteration, starting with 0)'
  75. );
  76. return $tokens;
  77. }
  78. }