addressfield_tokens.theme.inc 3.0 KB

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