addressfield_tokens.theme.inc 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. <?php
  2. /**
  3. * Implements theme_field();
  4. *
  5. * Themes an address according to the default renderer.
  6. */
  7. function theme_addressfield_formatter($vars) {
  8. $address = $vars['address'];
  9. $handlers = $vars['handlers'];
  10. $out = addressfield_generate($address, $handlers, array('mode' => 'render'));
  11. return '<div class="addressfield">' . render($out) . '</div>';
  12. }
  13. /**
  14. * Implements theme_field();
  15. *
  16. * Themes an address field into "city state, country"
  17. */
  18. function theme_addressfield_formatter__citystate($vars) {
  19. $loc = $vars['address'];
  20. // Determine which location components to render
  21. $out = array();
  22. if (!empty($loc['locality'])) {
  23. $out[] = $loc['locality'];
  24. }
  25. if (!empty($loc['administrative_area'])) {
  26. $out[] = $loc['administrative_area'];
  27. }
  28. if ($loc['country'] != addressfield_tokens_default_country() && $country_name = _addressfield_tokens_country($loc['country'])) {
  29. $out[] = $country_name;
  30. }
  31. // If there's no location, render an alternate
  32. if (empty($out)) {
  33. $out[] = 'Undefined';
  34. }
  35. // Render the location components
  36. $output = '<span class="addressfield-citystate">' . implode(', ', $out) . '</span>';
  37. return $output;
  38. }
  39. /**
  40. * Implements theme_field();
  41. *
  42. * Themes an address field into "name, street1, street2, city state zip country"
  43. */
  44. function theme_addressfield_formatter__linear($vars) {
  45. $loc = $vars['address'];
  46. // Determine which location components to render
  47. $out = array();
  48. if (!empty($loc['name_line']) && $vars['name_line']) {
  49. $out[] = $loc['name_line'];
  50. }
  51. if (!empty($loc['organisation_name']) && $vars['organisation_name']) {
  52. $out[] = $loc['organisation_name'];
  53. }
  54. if (!empty($loc['thoroughfare'])) {
  55. $out[] = $loc['thoroughfare'];
  56. }
  57. if (!empty($loc['premise']) && $vars['premise']) {
  58. $out[] = $loc['premise'];
  59. }
  60. if (!empty($loc['locality'])) {
  61. $out[] = $loc['locality'];
  62. }
  63. if (!empty($loc['administrative_area'])) {
  64. $out[] = $loc['administrative_area'];
  65. }
  66. if (!empty($loc['postal_code'])) {
  67. $out[] = $loc['postal_code'];
  68. }
  69. if ($loc['country'] != addressfield_tokens_default_country() && $country_name = _addressfield_tokens_country($loc['country'])) {
  70. $out[] = $country_name;
  71. }
  72. // Render the location components
  73. $output = implode(', ', $out);
  74. return $output;
  75. }
  76. function theme_addressfield_formatter__components($vars) {
  77. $loc = $vars['address'];
  78. $components = $vars['components'];
  79. $separator = $vars['separator'];
  80. $out = array();
  81. foreach ($components as $key) {
  82. if (!empty($loc[$key])) {
  83. $out[$key] = $loc[$key];
  84. }
  85. elseif ($key == 'country_full' && !empty($loc['country'])) {
  86. $out[$key] = _addressfield_tokens_country($loc['country']);
  87. }
  88. elseif ($key == 'administrative_area_full' && !empty($loc['country']) && !empty($loc['administrative_area'])) {
  89. $out[$key] = _addressfield_tokens_state($loc['country'], $loc['administrative_area']);
  90. }
  91. }
  92. return filter_xss(implode($separator, $out));
  93. }