1 |
85ad3d82
|
Assos Assos
|
<?php
|
2 |
|
|
|
3 |
|
|
/**
|
4 |
|
|
* @file
|
5 |
|
|
* The default format for adresses.
|
6 |
|
|
*/
|
7 |
|
|
|
8 |
|
|
$plugin = array(
|
9 |
|
|
'title' => t('Address form (country-specific)'),
|
10 |
|
|
'format callback' => 'addressfield_format_address_generate',
|
11 |
|
|
'type' => 'address',
|
12 |
|
|
'weight' => -100,
|
13 |
|
|
);
|
14 |
|
|
|
15 |
|
|
/**
|
16 |
|
|
* Format callback.
|
17 |
|
|
*
|
18 |
|
|
* @see CALLBACK_addressfield_format_callback()
|
19 |
|
|
*/
|
20 |
|
|
function addressfield_format_address_generate(&$format, $address, $context = array()) {
|
21 |
|
|
// We start with a reasonable default: a simple block format suitable
|
22 |
|
|
// for international shipping. We extend it with country-specific heuristics
|
23 |
|
|
// below.
|
24 |
|
|
|
25 |
|
|
// The street block.
|
26 |
|
|
$format['street_block'] = array(
|
27 |
|
|
'#type' => 'addressfield_container',
|
28 |
|
|
'#attributes' => array(
|
29 |
|
|
'class' => array('street-block'),
|
30 |
|
|
),
|
31 |
|
|
'#weight' => 0,
|
32 |
|
|
);
|
33 |
|
|
$format['street_block']['thoroughfare'] = array(
|
34 |
|
|
'#title' => t('Address 1'),
|
35 |
|
|
'#tag' => 'div',
|
36 |
|
|
'#attributes' => array(
|
37 |
|
|
'class' => array('thoroughfare'),
|
38 |
|
|
'x-autocompletetype' => 'address-line1',
|
39 |
|
|
'autocomplete' => 'address-line1',
|
40 |
|
|
),
|
41 |
|
|
'#size' => 30,
|
42 |
|
|
// The #required will be automatically set to FALSE when processing.
|
43 |
|
|
'#required' => TRUE,
|
44 |
|
|
);
|
45 |
|
|
$format['street_block']['premise'] = array(
|
46 |
|
|
'#title' => t('Address 2'),
|
47 |
|
|
'#tag' => 'div',
|
48 |
|
|
'#attributes' => array(
|
49 |
|
|
'class' => array('premise'),
|
50 |
|
|
'x-autocompletetype' => 'address-line2',
|
51 |
|
|
'autocomplete' => 'address-line2',
|
52 |
|
|
),
|
53 |
|
|
'#size' => 30,
|
54 |
|
|
);
|
55 |
|
|
$format['locality_block'] = array(
|
56 |
|
|
'#type' => 'addressfield_container',
|
57 |
|
|
'#attributes' => array(
|
58 |
|
|
'class' => array('addressfield-container-inline', 'locality-block', 'country-' . $address['country']),
|
59 |
|
|
),
|
60 |
|
|
'#weight' => 50,
|
61 |
|
|
);
|
62 |
|
|
$format['locality_block']['#attached']['css'][] = drupal_get_path('module', 'addressfield') . '/addressfield.css';
|
63 |
|
|
$format['locality_block']['postal_code'] = array(
|
64 |
|
|
'#title' => t('Postal code'),
|
65 |
|
|
'#size' => 10,
|
66 |
|
|
'#required' => TRUE,
|
67 |
|
|
'#attributes' => array(
|
68 |
|
|
'class' => array('postal-code'),
|
69 |
|
|
'x-autocompletetype' => 'postal-code',
|
70 |
|
|
'autocomplete' => 'postal-code',
|
71 |
|
|
),
|
72 |
|
|
);
|
73 |
|
|
$format['locality_block']['locality'] = array(
|
74 |
|
|
'#title' => t('City'),
|
75 |
|
|
'#size' => 30,
|
76 |
|
|
'#required' => TRUE,
|
77 |
|
|
'#prefix' => ' ',
|
78 |
|
|
'#attributes' => array(
|
79 |
|
|
'class' => array('locality'),
|
80 |
|
|
'x-autocompletetype' => 'locality',
|
81 |
|
|
'autocomplete' => 'locality',
|
82 |
|
|
),
|
83 |
|
|
);
|
84 |
|
|
$format['country'] = array(
|
85 |
|
|
'#title' => t('Country'),
|
86 |
|
|
'#options' => _addressfield_country_options_list(),
|
87 |
|
|
'#render_option_value' => TRUE,
|
88 |
|
|
'#required' => TRUE,
|
89 |
|
|
'#attributes' => array(
|
90 |
|
|
'class' => array('country'),
|
91 |
|
|
'x-autocompletetype' => 'country',
|
92 |
|
|
'autocomplete' => 'country',
|
93 |
|
|
),
|
94 |
|
|
'#weight' => 100,
|
95 |
|
|
);
|
96 |
|
|
|
97 |
|
|
// Those countries do not seem to have a relevant postal code.
|
98 |
|
|
static $countries_no_postal_code = array('AF', 'AG', 'AL', 'AO', 'BB', 'BI', 'BJ', 'BO', 'BS', 'BW', 'BZ', 'CF', 'CG', 'CM', 'CO', 'DJ', 'DM', 'EG', 'ER', 'FJ', 'GD', 'GH', 'GM', 'GQ', 'GY', 'HK', 'IE', 'KI', 'KM', 'KP', 'KY', 'LC', 'LY', 'ML', 'MR', 'NA', 'NR', 'RW', 'SB', 'SC', 'SL', 'SR', 'ST', 'TD', 'TG', 'TL', 'TO', 'TT', 'TV', 'TZ', 'UG', 'VC', 'VU', 'WS', 'ZW');
|
99 |
|
|
if (in_array($address['country'], $countries_no_postal_code)) {
|
100 |
|
|
unset($format['locality_block']['postal_code']);
|
101 |
|
|
|
102 |
|
|
// Remove the prefix from the first widget of the block.
|
103 |
|
|
$element_children = element_children($format['locality_block']);
|
104 |
|
|
$first_child = reset($element_children);
|
105 |
|
|
unset($format['locality_block'][$first_child]['#prefix']);
|
106 |
|
|
}
|
107 |
|
|
|
108 |
|
|
// Those countries generally use the administrative area in postal addresses.
|
109 |
|
|
static $countries_administrative_area = array('AR', 'AU', 'BR', 'BS', 'BY', 'BZ', 'CA', 'CN', 'DO', 'EG', 'ES', 'FJ', 'FM', 'GB', 'HN', 'ID', 'IE', 'IN', 'IT', 'JO', 'JP', 'KI', 'KN', 'KR', 'KW', 'KY', 'KZ', 'MX', 'MY', 'MZ', 'NG', 'NI', 'NR', 'NZ', 'OM', 'PA', 'PF', 'PG', 'PH', 'PR', 'PW', 'RU', 'SM', 'SO', 'SR', 'SV', 'TH', 'TW', 'UA', 'US', 'UY', 'VE', 'VI', 'VN', 'YU', 'ZA');
|
110 |
|
|
if (in_array($address['country'], $countries_administrative_area)) {
|
111 |
|
|
$format['locality_block']['administrative_area'] = array(
|
112 |
|
|
'#title' => t('State', array(), array('context' => 'Territory of a country')),
|
113 |
|
|
'#size' => 10,
|
114 |
|
|
'#required' => TRUE,
|
115 |
|
|
'#prefix' => ' ',
|
116 |
|
|
'#attributes' => array(
|
117 |
|
|
'class' => array('state'),
|
118 |
|
|
'x-autocompletetype' => 'region',
|
119 |
|
|
'autocomplete' => 'region',
|
120 |
|
|
),
|
121 |
|
|
);
|
122 |
|
|
}
|
123 |
|
|
|
124 |
|
|
// A few countries have a well-known list of administrative divisions.
|
125 |
|
|
if ($address['country'] == 'US') {
|
126 |
|
|
$format['locality_block']['administrative_area']['#options'] = array(
|
127 |
|
|
'' => t('--'),
|
128 |
|
|
'AL' => t('Alabama'),
|
129 |
|
|
'AK' => t('Alaska'),
|
130 |
|
|
'AZ' => t('Arizona'),
|
131 |
|
|
'AR' => t('Arkansas'),
|
132 |
|
|
'CA' => t('California'),
|
133 |
|
|
'CO' => t('Colorado'),
|
134 |
|
|
'CT' => t('Connecticut'),
|
135 |
|
|
'DE' => t('Delaware'),
|
136 |
|
|
'DC' => t('District Of Columbia'),
|
137 |
|
|
'FL' => t('Florida'),
|
138 |
|
|
'GA' => t('Georgia'),
|
139 |
|
|
'HI' => t('Hawaii'),
|
140 |
|
|
'ID' => t('Idaho'),
|
141 |
|
|
'IL' => t('Illinois'),
|
142 |
|
|
'IN' => t('Indiana'),
|
143 |
|
|
'IA' => t('Iowa'),
|
144 |
|
|
'KS' => t('Kansas'),
|
145 |
|
|
'KY' => t('Kentucky'),
|
146 |
|
|
'LA' => t('Louisiana'),
|
147 |
|
|
'ME' => t('Maine'),
|
148 |
|
|
'MD' => t('Maryland'),
|
149 |
|
|
'MA' => t('Massachusetts'),
|
150 |
|
|
'MI' => t('Michigan'),
|
151 |
|
|
'MN' => t('Minnesota'),
|
152 |
|
|
'MS' => t('Mississippi'),
|
153 |
|
|
'MO' => t('Missouri'),
|
154 |
|
|
'MT' => t('Montana'),
|
155 |
|
|
'NE' => t('Nebraska'),
|
156 |
|
|
'NV' => t('Nevada'),
|
157 |
|
|
'NH' => t('New Hampshire'),
|
158 |
|
|
'NJ' => t('New Jersey'),
|
159 |
|
|
'NM' => t('New Mexico'),
|
160 |
|
|
'NY' => t('New York'),
|
161 |
|
|
'NC' => t('North Carolina'),
|
162 |
|
|
'ND' => t('North Dakota'),
|
163 |
|
|
'OH' => t('Ohio'),
|
164 |
|
|
'OK' => t('Oklahoma'),
|
165 |
|
|
'OR' => t('Oregon'),
|
166 |
|
|
'PA' => t('Pennsylvania'),
|
167 |
|
|
'RI' => t('Rhode Island'),
|
168 |
|
|
'SC' => t('South Carolina'),
|
169 |
|
|
'SD' => t('South Dakota'),
|
170 |
|
|
'TN' => t('Tennessee'),
|
171 |
|
|
'TX' => t('Texas'),
|
172 |
|
|
'UT' => t('Utah'),
|
173 |
|
|
'VT' => t('Vermont'),
|
174 |
|
|
'VA' => t('Virginia'),
|
175 |
|
|
'WA' => t('Washington'),
|
176 |
|
|
'WV' => t('West Virginia'),
|
177 |
|
|
'WI' => t('Wisconsin'),
|
178 |
|
|
'WY' => t('Wyoming'),
|
179 |
|
|
' ' => t('--'),
|
180 |
|
|
'AA' => t('Armed Forces (Americas)'),
|
181 |
|
|
'AE' => t('Armed Forces (Europe, Canada, Middle East, Africa)'),
|
182 |
|
|
'AP' => t('Armed Forces (Pacific)'),
|
183 |
|
|
'AS' => t('American Samoa'),
|
184 |
|
|
'FM' => t('Federated States of Micronesia'),
|
185 |
|
|
'GU' => t('Guam'),
|
186 |
|
|
'MH' => t('Marshall Islands'),
|
187 |
|
|
'MP' => t('Northern Mariana Islands'),
|
188 |
|
|
'PW' => t('Palau'),
|
189 |
|
|
'PR' => t('Puerto Rico'),
|
190 |
|
|
'VI' => t('Virgin Islands'),
|
191 |
|
|
);
|
192 |
|
|
$format['locality_block']['postal_code']['#title'] = t('ZIP Code');
|
193 |
|
|
|
194 |
|
|
if ($context['mode'] == 'render') {
|
195 |
|
|
$format['locality_block']['locality']['#suffix'] = ',';
|
196 |
|
|
}
|
197 |
|
|
}
|
198 |
|
|
else if ($address['country'] == 'IT') {
|
199 |
|
|
$format['locality_block']['administrative_area']['#options'] = array(
|
200 |
|
|
'' => t('--'),
|
201 |
|
|
'AG' => t('Agrigento'),
|
202 |
|
|
'AL' => t('Alessandria'),
|
203 |
|
|
'AN' => t('Ancona'),
|
204 |
|
|
'AO' => t("Valle d'Aosta/Vallée d'Aoste"),
|
205 |
|
|
'AP' => t('Ascoli Piceno'),
|
206 |
|
|
'AQ' => t("L'Aquila"),
|
207 |
|
|
'AR' => t('Arezzo'),
|
208 |
|
|
'AT' => t('Asti'),
|
209 |
|
|
'AV' => t('Avellino'),
|
210 |
|
|
'BA' => t('Bari'),
|
211 |
|
|
'BG' => t('Bergamo'),
|
212 |
|
|
'BI' => t('Biella'),
|
213 |
|
|
'BL' => t('Belluno'),
|
214 |
|
|
'BN' => t('Benevento'),
|
215 |
|
|
'BO' => t('Bologna'),
|
216 |
|
|
'BR' => t('Brindisi'),
|
217 |
|
|
'BS' => t('Brescia'),
|
218 |
|
|
'BT' => t('Barletta-Andria-Trani'),
|
219 |
|
|
'BZ' => t('Bolzano/Bozen'),
|
220 |
|
|
'CA' => t('Cagliari'),
|
221 |
|
|
'CB' => t('Campobasso'),
|
222 |
|
|
'CE' => t('Caserta'),
|
223 |
|
|
'CH' => t('Chieti'),
|
224 |
|
|
'CI' => t('Carbonia-Iglesias'),
|
225 |
|
|
'CL' => t('Caltanissetta'),
|
226 |
|
|
'CN' => t('Cuneo'),
|
227 |
|
|
'CO' => t('Como'),
|
228 |
|
|
'CR' => t('Cremona'),
|
229 |
|
|
'CS' => t('Cosenza'),
|
230 |
|
|
'CT' => t('Catania'),
|
231 |
|
|
'CZ' => t('Catanzaro'),
|
232 |
|
|
'EN' => t('Enna'),
|
233 |
|
|
'FC' => t('Forlì-Cesena'),
|
234 |
|
|
'FE' => t('Ferrara'),
|
235 |
|
|
'FG' => t('Foggia'),
|
236 |
|
|
'FI' => t('Firenze'),
|
237 |
|
|
'FM' => t('Fermo'),
|
238 |
|
|
'FR' => t('Frosinone'),
|
239 |
|
|
'GE' => t('Genova'),
|
240 |
|
|
'GO' => t('Gorizia'),
|
241 |
|
|
'GR' => t('Grosseto'),
|
242 |
|
|
'IM' => t('Imperia'),
|
243 |
|
|
'IS' => t('Isernia'),
|
244 |
|
|
'KR' => t('Crotone'),
|
245 |
|
|
'LC' => t('Lecco'),
|
246 |
|
|
'LE' => t('Lecce'),
|
247 |
|
|
'LI' => t('Livorno'),
|
248 |
|
|
'LO' => t('Lodi'),
|
249 |
|
|
'LT' => t('Latina'),
|
250 |
|
|
'LU' => t('Lucca'),
|
251 |
|
|
'MB' => t('Monza e Brianza'),
|
252 |
|
|
'MC' => t('Macerata'),
|
253 |
|
|
'ME' => t('Messina'),
|
254 |
|
|
'MI' => t('Milano'),
|
255 |
|
|
'MN' => t('Mantova'),
|
256 |
|
|
'MO' => t('Modena'),
|
257 |
|
|
'MS' => t('Massa-Carrara'),
|
258 |
|
|
'MT' => t('Matera'),
|
259 |
|
|
'NA' => t('Napoli'),
|
260 |
|
|
'NO' => t('Novara'),
|
261 |
|
|
'NU' => t('Nuoro'),
|
262 |
|
|
'OG' => t('Ogliastra'),
|
263 |
|
|
'OR' => t('Oristano'),
|
264 |
|
|
'OT' => t('Olbia-Tempio'),
|
265 |
|
|
'PA' => t('Palermo'),
|
266 |
|
|
'PC' => t('Piacenza'),
|
267 |
|
|
'PD' => t('Padova'),
|
268 |
|
|
'PE' => t('Pescara'),
|
269 |
|
|
'PG' => t('Perugia'),
|
270 |
|
|
'PI' => t('Pisa'),
|
271 |
|
|
'PN' => t('Pordenone'),
|
272 |
|
|
'PO' => t('Prato'),
|
273 |
|
|
'PR' => t('Parma'),
|
274 |
|
|
'PT' => t('Pistoia'),
|
275 |
|
|
'PU' => t('Pesaro e Urbino'),
|
276 |
|
|
'PV' => t('Pavia'),
|
277 |
|
|
'PZ' => t('Potenza'),
|
278 |
|
|
'RA' => t('Ravenna'),
|
279 |
|
|
'RC' => t('Reggio di Calabria'),
|
280 |
|
|
'RE' => t("Reggio nell'Emilia"),
|
281 |
|
|
'RG' => t('Ragusa'),
|
282 |
|
|
'RI' => t('Rieti'),
|
283 |
|
|
'RM' => t('Roma'),
|
284 |
|
|
'RN' => t('Rimini'),
|
285 |
|
|
'RO' => t('Rovigo'),
|
286 |
|
|
'SA' => t('Salerno'),
|
287 |
|
|
'SI' => t('Siena'),
|
288 |
|
|
'SO' => t('Sondrio'),
|
289 |
|
|
'SP' => t('La Spezia'),
|
290 |
|
|
'SR' => t('Siracusa'),
|
291 |
|
|
'SS' => t('Sassari'),
|
292 |
|
|
'SV' => t('Savona'),
|
293 |
|
|
'TA' => t('Taranto'),
|
294 |
|
|
'TE' => t('Teramo'),
|
295 |
|
|
'TN' => t('Trento'),
|
296 |
|
|
'TO' => t('Torino'),
|
297 |
|
|
'TP' => t('Trapani'),
|
298 |
|
|
'TR' => t('Terni'),
|
299 |
|
|
'TS' => t('Trieste'),
|
300 |
|
|
'TV' => t('Treviso'),
|
301 |
|
|
'UD' => t('Udine'),
|
302 |
|
|
'VA' => t('Varese'),
|
303 |
|
|
'VB' => t('Verbano-Cusio-Ossola'),
|
304 |
|
|
'VC' => t('Vercelli'),
|
305 |
|
|
'VE' => t('Venezia'),
|
306 |
|
|
'VI' => t('Vicenza'),
|
307 |
|
|
'VR' => t('Verona'),
|
308 |
|
|
'VS' => t('Medio Campidano'),
|
309 |
|
|
'VT' => t('Viterbo'),
|
310 |
|
|
'VV' => t('Vibo Valentia'),
|
311 |
|
|
);
|
312 |
|
|
$format['locality_block']['administrative_area']['#title'] = t('Province');
|
313 |
|
|
}
|
314 |
|
|
elseif ($address['country'] == 'BR') {
|
315 |
|
|
$format['locality_block']['dependent_locality'] = array(
|
316 |
|
|
'#title' => t('Neighborhood'),
|
317 |
|
|
'#tag' => 'div',
|
318 |
|
|
'#attributes' => array('class' => array('dependent-locality')),
|
319 |
|
|
'#size' => 25,
|
320 |
|
|
'#render_option_value' => FALSE,
|
321 |
|
|
);
|
322 |
|
|
$format['locality_block']['administrative_area']['#render_option_value'] = TRUE;
|
323 |
|
|
$format['locality_block']['administrative_area']['#options'] = array(
|
324 |
|
|
'' => t('--'),
|
325 |
|
|
'AC' => t('Acre'),
|
326 |
|
|
'AL' => t('Alagoas'),
|
327 |
|
|
'AM' => t('Amazonas'),
|
328 |
|
|
'AP' => t('Amapá'),
|
329 |
|
|
'BA' => t('Bahia'),
|
330 |
|
|
'CE' => t('Ceará'),
|
331 |
|
|
'DF' => t('Distrito Federal'),
|
332 |
|
|
'ES' => t('Espírito Santo'),
|
333 |
|
|
'GO' => t('Goiás'),
|
334 |
|
|
'MA' => t('Maranhão'),
|
335 |
|
|
'MG' => t('Minas Gerais'),
|
336 |
|
|
'MS' => t('Mato Grosso do Sul'),
|
337 |
|
|
'MT' => t('Mato Grosso'),
|
338 |
|
|
'PA' => t('Pará'),
|
339 |
|
|
'PB' => t('Paraíba'),
|
340 |
|
|
'PE' => t('Pernambuco'),
|
341 |
|
|
'PI' => t('Piauí'),
|
342 |
|
|
'PR' => t('Paraná'),
|
343 |
|
|
'RJ' => t('Rio de Janeiro'),
|
344 |
|
|
'RN' => t('Rio Grande do Norte'),
|
345 |
|
|
'RO' => t('Rondônia'),
|
346 |
|
|
'RR' => t('Roraima'),
|
347 |
|
|
'RS' => t('Rio Grande do Sul'),
|
348 |
|
|
'SC' => t('Santa Catarina'),
|
349 |
|
|
'SE' => t('Sergipe'),
|
350 |
|
|
'SP' => t('São Paulo'),
|
351 |
|
|
'TO' => t('Tocantins'),
|
352 |
|
|
);
|
353 |
|
|
// Change some titles to make translation easier.
|
354 |
|
|
$format['street_block']['#attributes'] = array(
|
355 |
|
|
'class' => array('addressfield-container-inline'),
|
356 |
|
|
);
|
357 |
|
|
$format['street_block']['thoroughfare'] = array(
|
358 |
|
|
'#title' => t('Thoroughfare'),
|
359 |
|
|
'#tag' => NULL,
|
360 |
|
|
'#attributes' => array('class' => array('thoroughfare')),
|
361 |
|
|
'#size' => 30,
|
362 |
|
|
// The #required will be automatically set to FALSE when processing.
|
363 |
|
|
'#required' => TRUE,
|
364 |
|
|
);
|
365 |
|
|
$format['street_block']['premise'] = array(
|
366 |
|
|
'#title' => t('Complement'),
|
367 |
|
|
'#tag' => NULL,
|
368 |
|
|
'#attributes' => array('class' => array('premise')),
|
369 |
|
|
'#size' => 20,
|
370 |
|
|
'#prefix' => ', ',
|
371 |
|
|
);
|
372 |
|
|
$format['locality_block']['locality']['#suffix'] = ' - ';
|
373 |
|
|
// Hide suffixes and prefixes while in form.
|
374 |
|
|
if ($context['mode'] == 'form') {
|
375 |
|
|
$format['street_block']['premise']['#prefix'] = NULL;
|
376 |
|
|
$format['street_block']['premise']['#suffix'] = NULL;
|
377 |
|
|
$format['locality_block']['locality']['#suffix'] = NULL;
|
378 |
|
|
}
|
379 |
|
|
// Render an extra field for 'Neighborhood'.
|
380 |
|
|
$format['locality_block']['dependent_locality']['#render_option_value'] = TRUE;
|
381 |
|
|
// Change some weights to conform local standards
|
382 |
|
|
// Neighborhood.
|
383 |
|
|
$format['locality_block']['dependent_locality']['#weight'] = 0;
|
384 |
|
|
// City.
|
385 |
|
|
$format['locality_block']['locality']['#weight'] = 5;
|
386 |
|
|
// State.
|
387 |
|
|
$format['locality_block']['administrative_area']['#weight'] = 10;
|
388 |
|
|
// Postal Code.
|
389 |
|
|
$format['locality_block']['postal_code']['#weight'] = 16;
|
390 |
|
|
$format['locality_block']['postal_code']['#tag'] = 'div';
|
391 |
|
|
}
|
392 |
|
|
else if ($address['country'] == 'CA') {
|
393 |
|
|
$format['locality_block']['administrative_area']['#options'] = array(
|
394 |
|
|
'' => t('--'),
|
395 |
|
|
'AB' => t('Alberta'),
|
396 |
|
|
'BC' => t('British Columbia'),
|
397 |
|
|
'MB' => t('Manitoba'),
|
398 |
|
|
'NB' => t('New Brunswick'),
|
399 |
|
|
'NL' => t('Newfoundland and Labrador'),
|
400 |
|
|
'NT' => t('Northwest Territories'),
|
401 |
|
|
'NS' => t('Nova Scotia'),
|
402 |
|
|
'NU' => t('Nunavut'),
|
403 |
|
|
'ON' => t('Ontario'),
|
404 |
|
|
'PE' => t('Prince Edward Island'),
|
405 |
|
|
'QC' => t('Quebec'),
|
406 |
|
|
'SK' => t('Saskatchewan'),
|
407 |
|
|
'YT' => t('Yukon Territory'),
|
408 |
|
|
);
|
409 |
|
|
$format['locality_block']['administrative_area']['#title'] = t('Province');
|
410 |
|
|
|
411 |
|
|
if ($context['mode'] == 'render') {
|
412 |
|
|
$format['locality_block']['locality']['#suffix'] = ',';
|
413 |
|
|
}
|
414 |
|
|
}
|
415 |
|
|
else if ($address['country'] == 'AU') {
|
416 |
|
|
$format['locality_block']['administrative_area']['#options'] = array(
|
417 |
|
|
'' => t('--'),
|
418 |
|
|
'ACT' => t('Australian Capital Territory'),
|
419 |
|
|
'NSW' => t('New South Wales'),
|
420 |
|
|
'NT' => t('Northern Territory'),
|
421 |
|
|
'QLD' => t('Queensland'),
|
422 |
|
|
'SA' => t('South Australia'),
|
423 |
|
|
'TAS' => t('Tasmania'),
|
424 |
|
|
'VIC' => t('Victoria'),
|
425 |
|
|
'WA' => t('Western Australia'),
|
426 |
|
|
);
|
427 |
|
|
}
|
428 |
|
|
else if ($address['country'] == 'NZ') {
|
429 |
|
|
$format['locality_block']['locality']['#title'] = ('Town/City');
|
430 |
|
|
$format['locality_block']['postal_code']['#title'] = t('Postcode');
|
431 |
|
|
$format['locality_block']['administrative_area']['#render_option_value'] = TRUE;
|
432 |
|
|
$format['locality_block']['administrative_area']['#title'] = t('Region');
|
433 |
|
|
$format['locality_block']['administrative_area']['#required'] = FALSE;
|
434 |
|
|
$format['locality_block']['administrative_area']['#options'] = array(
|
435 |
|
|
'' => t('--'),
|
436 |
|
|
'AUK' => t('Auckland'),
|
437 |
|
|
'BOP' => t('Bay of Plenty'),
|
438 |
|
|
'CAN' => t('Canterbury'),
|
439 |
|
|
'HKB' => t("Hawke's Bay"),
|
440 |
|
|
'MWT' => t('Manawatu-Wanganui'),
|
441 |
|
|
'NTL' => t('Northland'),
|
442 |
|
|
'OTA' => t('Otago'),
|
443 |
|
|
'STL' => t('Southland'),
|
444 |
|
|
'TKI' => t('Taranaki'),
|
445 |
|
|
'WKO' => t('Waikato'),
|
446 |
|
|
'WGN' => t('Wellington'),
|
447 |
|
|
'WTC' => t('West Coast'),
|
448 |
|
|
'GIS' => t('Gisborne District'),
|
449 |
|
|
'MBH' => t('Marlborough District'),
|
450 |
|
|
'NSN' => t('Nelson'),
|
451 |
|
|
'TAS' => t('Tasman District'),
|
452 |
|
|
'CIT' => t('Chatham Islands Territory'),
|
453 |
|
|
);
|
454 |
|
|
}
|
455 |
|
|
|
456 |
|
|
// Those countries tend to put the postal code after the locality.
|
457 |
|
|
static $countries_postal_code_after_locality = array('AU', 'BD', 'BF', 'BH', 'BM', 'BN', 'BT', 'CA', 'FM', 'GB', 'ID', 'IN', 'JM', 'JO', 'KH', 'LB', 'LS', 'LV', 'MM', 'MN', 'MV', 'MW', 'NG', 'NP', 'NZ', 'PE', 'PK', 'PR', 'PW', 'SA', 'SG', 'SO', 'TH', 'US', 'VI', 'VG', 'VN');
|
458 |
|
|
if (in_array($address['country'], $countries_postal_code_after_locality)) {
|
459 |
|
|
// Take the widget out of the array.
|
460 |
|
|
$postal_code_widget = $format['locality_block']['postal_code'];
|
461 |
|
|
$postal_code_widget['#prefix'] = ' ';
|
462 |
|
|
unset($format['locality_block']['postal_code']);
|
463 |
|
|
|
464 |
|
|
// Add it back.
|
465 |
|
|
$format['locality_block']['postal_code'] = $postal_code_widget;
|
466 |
|
|
|
467 |
|
|
// Remove the prefix from the first widget of the block.
|
468 |
|
|
$element_children = element_children($format['locality_block']);
|
469 |
|
|
$first_child = reset($element_children);
|
470 |
|
|
unset($format['locality_block'][$first_child]['#prefix']);
|
471 |
|
|
}
|
472 |
|
|
|
473 |
|
|
// GB-specific tweaks
|
474 |
|
|
if ($address['country'] == 'GB') {
|
475 |
|
|
// Locality
|
476 |
|
|
$format['locality_block']['locality'] = array_merge(
|
477 |
|
|
$format['locality_block']['locality'],
|
478 |
|
|
array(
|
479 |
|
|
'#title' => t('Town/City'),
|
480 |
|
|
'#weight' => 40,
|
481 |
|
|
'#prefix' => '',
|
482 |
|
|
'#tag' => 'div',
|
483 |
|
|
)
|
484 |
|
|
);
|
485 |
|
|
|
486 |
|
|
// Administrative
|
487 |
|
|
$format['locality_block']['administrative_area'] = array_merge(
|
488 |
|
|
$format['locality_block']['administrative_area'],
|
489 |
|
|
array(
|
490 |
|
|
'#title' => t('County'),
|
491 |
|
|
'#required' => FALSE,
|
492 |
|
|
'#weight' => 50,
|
493 |
|
|
'#size' => 30,
|
494 |
|
|
'#prefix' => '',
|
495 |
|
|
'#tag' => 'div',
|
496 |
|
|
)
|
497 |
|
|
);
|
498 |
|
|
|
499 |
|
|
// Postal code
|
500 |
|
|
$format['locality_block']['postal_code'] = array_merge(
|
501 |
|
|
$format['locality_block']['postal_code'],
|
502 |
|
|
array(
|
503 |
|
|
'#title' => t('Postcode'),
|
504 |
|
|
'#weight' => 60,
|
505 |
|
|
'#prefix' => '',
|
506 |
|
|
'#tag' => 'div',
|
507 |
|
|
)
|
508 |
|
|
);
|
509 |
|
|
}
|
510 |
|
|
|
511 |
|
|
if ($context['mode'] == 'form') {
|
512 |
|
|
// Provide a wrapper ID for AJAX replacement based on country selection.
|
513 |
|
|
if (!isset($format['#wrapper_id'])) {
|
514 |
|
|
$format['#wrapper_id'] = drupal_html_id('addressfield-wrapper');
|
515 |
|
|
$format['#prefix'] = '<div id="' . $format['#wrapper_id'] . '">';
|
516 |
|
|
$format['#suffix'] = '</div>';
|
517 |
|
|
}
|
518 |
|
|
|
519 |
|
|
// Form mode, move the country selector to the top of the form.
|
520 |
|
|
$format['country']['#weight'] = -10;
|
521 |
|
|
|
522 |
|
|
// Limit it to the countries supported by the widget.
|
523 |
|
|
if (isset($context['field'])) {
|
524 |
|
|
$format['country']['#options'] = _addressfield_country_options_list($context['field'], $context['instance']);
|
525 |
|
|
}
|
526 |
|
|
|
527 |
|
|
// AJAX enable it.
|
528 |
|
|
$format['country']['#ajax'] = array(
|
529 |
|
|
'callback' => 'addressfield_standard_widget_refresh',
|
530 |
|
|
'wrapper' => $format['#wrapper_id'],
|
531 |
|
|
);
|
532 |
|
|
$format['country']['#element_validate'] = array('addressfield_standard_country_validate');
|
533 |
|
|
// Don't validate any element when the country is changed.
|
534 |
|
|
$format['country']['#limit_validation_errors'] = array();
|
535 |
|
|
|
536 |
|
|
if (isset($context['delta']) && $context['delta'] > 0) {
|
537 |
|
|
// On subsequent elements of a field, we make the country field non
|
538 |
|
|
// required and add a ' - None - ' option to it, so as to allow the
|
539 |
|
|
// user to remove the address by clearing the country field.
|
540 |
|
|
$format['country']['#required'] = FALSE;
|
541 |
|
|
$format['country']['#empty_value'] = '';
|
542 |
|
|
}
|
543 |
|
|
}
|
544 |
|
|
} |