Révision f066bdb5
Ajouté par Assos Assos il y a plus de 9 ans
drupal7/sites/all/modules/addressfield/plugins/format/address.inc | ||
---|---|---|
18 | 18 |
* @see CALLBACK_addressfield_format_callback() |
19 | 19 |
*/ |
20 | 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. |
|
21 |
// Load the predefined address format for the selected country. |
|
22 |
module_load_include('inc', 'addressfield', 'addressfield.address_formats'); |
|
23 |
$address_format = addressfield_get_address_format($address['country']); |
|
24 |
|
|
25 |
// Used to move certain fields to their own row. |
|
26 |
$clearfix = '<div class="clearfix"></div>'; |
|
24 | 27 |
|
25 | 28 |
// The street block. |
26 | 29 |
$format['street_block'] = array( |
... | ... | |
39 | 42 |
'autocomplete' => 'address-line1', |
40 | 43 |
), |
41 | 44 |
'#size' => 30, |
42 |
// The #required will be automatically set to FALSE when processing. |
|
43 | 45 |
'#required' => TRUE, |
44 | 46 |
); |
45 | 47 |
$format['street_block']['premise'] = array( |
... | ... | |
61 | 63 |
); |
62 | 64 |
$format['locality_block']['#attached']['css'][] = drupal_get_path('module', 'addressfield') . '/addressfield.css'; |
63 | 65 |
$format['locality_block']['postal_code'] = array( |
64 |
'#title' => t('Postal code'), |
|
66 |
'#title' => $address_format['postal_code_label'], |
|
67 |
'#required' => in_array('postal_code', $address_format['required_fields']), |
|
68 |
'#access' => in_array('postal_code', $address_format['used_fields']), |
|
65 | 69 |
'#size' => 10, |
66 |
'#required' => TRUE, |
|
67 | 70 |
'#attributes' => array( |
68 | 71 |
'class' => array('postal-code'), |
69 | 72 |
'x-autocompletetype' => 'postal-code', |
70 | 73 |
'autocomplete' => 'postal-code', |
71 | 74 |
), |
72 | 75 |
); |
76 |
$format['locality_block']['dependent_locality'] = array( |
|
77 |
'#title' => $address_format['dependent_locality_label'], |
|
78 |
'#required' => in_array('dependent_locality', $address_format['required_fields']), |
|
79 |
'#access' => in_array('dependent_locality', $address_format['used_fields']), |
|
80 |
'#size' => 25, |
|
81 |
'#tag' => 'div', |
|
82 |
'#attributes' => array( |
|
83 |
'class' => array('dependent-locality') |
|
84 |
), |
|
85 |
// Most formats place this field in its own row. |
|
86 |
'#suffix' => $clearfix, |
|
87 |
); |
|
73 | 88 |
$format['locality_block']['locality'] = array( |
74 |
'#title' => t('City'), |
|
89 |
'#title' => $address_format['locality_label'], |
|
90 |
'#required' => in_array('locality', $address_format['required_fields']), |
|
91 |
'#access' => in_array('locality', $address_format['used_fields']), |
|
75 | 92 |
'#size' => 30, |
76 |
'#required' => TRUE, |
|
77 | 93 |
'#prefix' => ' ', |
78 | 94 |
'#attributes' => array( |
79 | 95 |
'class' => array('locality'), |
... | ... | |
81 | 97 |
'autocomplete' => 'locality', |
82 | 98 |
), |
83 | 99 |
); |
100 |
$format['locality_block']['administrative_area'] = array( |
|
101 |
'#title' => $address_format['administrative_area_label'], |
|
102 |
'#required' => in_array('administrative_area', $address_format['required_fields']), |
|
103 |
'#access' => in_array('administrative_area', $address_format['used_fields']), |
|
104 |
'#empty_value' => '', |
|
105 |
'#size' => 10, |
|
106 |
'#prefix' => ' ', |
|
107 |
'#attributes' => array( |
|
108 |
'class' => array('state'), |
|
109 |
'x-autocompletetype' => 'region', |
|
110 |
'autocomplete' => 'region', |
|
111 |
), |
|
112 |
); |
|
84 | 113 |
$format['country'] = array( |
85 | 114 |
'#title' => t('Country'), |
86 | 115 |
'#options' => _addressfield_country_options_list(), |
... | ... | |
94 | 123 |
'#weight' => 100, |
95 | 124 |
); |
96 | 125 |
|
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 |
|
|
126 |
if (empty($format['locality_block']['postal_code']['#access'])) { |
|
102 | 127 |
// Remove the prefix from the first widget of the block. |
103 | 128 |
$element_children = element_children($format['locality_block']); |
104 | 129 |
$first_child = reset($element_children); |
105 | 130 |
unset($format['locality_block'][$first_child]['#prefix']); |
106 | 131 |
} |
107 | 132 |
|
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 |
); |
|
133 |
if (!empty($format['locality_block']['administrative_area']['#access'])) { |
|
134 |
// Set the predefined administrative areas, if found. |
|
135 |
module_load_include('inc', 'addressfield', 'addressfield.administrative_areas'); |
|
136 |
$administrative_areas = addressfield_get_administrative_areas($address['country']); |
|
137 |
$format['locality_block']['administrative_area']['#options'] = $administrative_areas; |
|
122 | 138 |
} |
123 | 139 |
|
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 |
|
|
140 |
// Country-specific customizations. |
|
141 |
if (in_array($address['country'], array('AU', 'NZ', 'RU'))) { |
|
142 |
// These countries don't use the "Address 2" line. |
|
143 |
// Leave it as a precaution, but hide the label to avoid confusing users. |
|
144 |
$format['street_block']['thoroughfare']['#title'] = t('Address'); |
|
145 |
$format['street_block']['premise']['#title_display'] = 'invisible'; |
|
146 |
} |
|
147 |
elseif ($address['country'] == 'US') { |
|
194 | 148 |
if ($context['mode'] == 'render') { |
195 | 149 |
$format['locality_block']['locality']['#suffix'] = ','; |
196 | 150 |
} |
197 | 151 |
} |
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 | 152 |
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 |
); |
|
153 |
$format['locality_block']['dependent_locality']['#suffix'] = $clearfix; |
|
154 |
$format['locality_block']['dependent_locality']['#tag'] = 'div'; |
|
322 | 155 |
$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 |
); |
|
156 |
$format['locality_block']['administrative_area']['#suffix'] = $clearfix; |
|
157 |
$format['locality_block']['postal_code']['#tag'] = 'div'; |
|
353 | 158 |
// Change some titles to make translation easier. |
354 | 159 |
$format['street_block']['#attributes'] = array( |
355 | 160 |
'class' => array('addressfield-container-inline'), |
356 | 161 |
); |
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 |
); |
|
162 |
$format['street_block']['thoroughfare']['#title'] = t('Thoroughfare'); |
|
163 |
$format['street_block']['thoroughfare']['#tag'] = NULL; |
|
365 | 164 |
$format['street_block']['premise'] = array( |
366 | 165 |
'#title' => t('Complement'), |
367 | 166 |
'#tag' => NULL, |
... | ... | |
376 | 175 |
$format['street_block']['premise']['#suffix'] = NULL; |
377 | 176 |
$format['locality_block']['locality']['#suffix'] = NULL; |
378 | 177 |
} |
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 | 178 |
} |
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 |
|
|
179 |
elseif ($address['country'] == 'CN') { |
|
180 |
$format['locality_block']['locality']['#suffix'] = $clearfix; |
|
181 |
} |
|
182 |
elseif ($address['country'] == 'CA') { |
|
411 | 183 |
if ($context['mode'] == 'render') { |
412 | 184 |
$format['locality_block']['locality']['#suffix'] = ','; |
413 | 185 |
} |
414 | 186 |
} |
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 |
); |
|
187 |
elseif ($address['country'] == 'GB') { |
|
188 |
$format['locality_block']['administrative_area']['#size'] = '30'; |
|
427 | 189 |
} |
428 |
else if ($address['country'] == 'NZ') { |
|
429 |
$format['locality_block']['locality']['#title'] = ('Town/City'); |
|
430 |
$format['locality_block']['postal_code']['#title'] = t('Postcode'); |
|
190 |
elseif ($address['country'] == 'ID') { |
|
431 | 191 |
$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 |
); |
|
192 |
$format['locality_block']['administrative_area']['#weight'] = 1; |
|
193 |
} |
|
194 |
elseif ($address['country'] == 'JP') { |
|
195 |
$format['locality_block']['#weight'] = 10; |
|
196 |
$format['locality_block']['postal_code']['#weight'] = 10; |
|
197 |
$format['locality_block']['postal_code']['#tag'] = 'div'; |
|
198 |
$format['locality_block']['postal_code']['#size'] = 30; |
|
199 |
$format['locality_block']['administrative_area']['#weight'] = 20; |
|
200 |
$format['locality_block']['administrative_area']['#size'] = 30; |
|
201 |
$format['locality_block']['administrative_area']['#render_option_value'] = TRUE; |
|
202 |
$format['locality_block']['locality']['#weight'] = 30; |
|
203 |
$format['street_block']['#weight'] = 20; |
|
204 |
} |
|
205 |
elseif ($address['country'] == 'PE') { |
|
206 |
$format['locality_block']['administrative_area']['#weight'] = 1; |
|
207 |
$format['locality_block']['locality']['#weight'] = 2; |
|
208 |
} |
|
209 |
elseif ($address['country'] == 'PH' || $address['country'] == 'TH') { |
|
210 |
$format['locality_block']['dependent_locality']['#suffix'] = ''; |
|
211 |
$format['locality_block']['locality']['#suffix'] = $clearfix; |
|
454 | 212 |
} |
455 | 213 |
|
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'); |
|
214 |
// These countries show every field in its own row. |
|
215 |
$countries_field_per_row = array( |
|
216 |
'AM', 'EG', 'FK', 'GB', 'GG', 'GS', 'HK', 'HU', 'IE', 'IM', 'IO', 'JE', 'JM', |
|
217 |
'JP', 'KE', 'KR', 'KZ', 'LK', 'PA', 'PN', 'RU', 'SC', 'SH', 'SZ', 'TC', 'UA', |
|
218 |
'VG', 'ZA', |
|
219 |
); |
|
220 |
if (in_array($address['country'], $countries_field_per_row)) { |
|
221 |
$format['locality_block']['#attributes']['class'][0] = 'addressfield-container'; |
|
222 |
$format['locality_block']['postal_code']['#prefix'] = ''; |
|
223 |
$format['locality_block']['postal_code']['#tag'] = 'div'; |
|
224 |
$format['locality_block']['locality']['#prefix'] = ''; |
|
225 |
$format['locality_block']['locality']['#tag'] = 'div'; |
|
226 |
$format['locality_block']['administrative_area']['#prefix'] = ''; |
|
227 |
$format['locality_block']['administrative_area']['#tag'] = 'div'; |
|
228 |
} |
|
229 |
|
|
230 |
// These countries tend to put the postal code after the locality. |
|
231 |
$countries_postal_code_after_locality = array( |
|
232 |
'AS', 'AU', 'BD', 'BF', 'BH', 'BM', 'BN', 'BR', 'BT', 'CA', 'CC', 'CN', 'CX', |
|
233 |
'EG', 'FK', 'FM', 'GB', 'GG', 'GS', 'GU', 'HN', 'HU', 'ID', 'IL', 'IM', 'IN', |
|
234 |
'IO', 'IQ', 'IR', 'JE', 'JO', 'JP', 'KE', 'KH', 'KR', 'LB', 'LK', 'LS', 'LV', |
|
235 |
'MH', 'MM', 'MN', 'MP', 'MT', 'MV', 'MX', 'MY', 'NF', 'NG', 'NP', 'NZ', 'PG', |
|
236 |
'PH', 'PK', 'PN', 'PR', 'PW', 'RU', 'SA', 'SH', 'SO', 'SZ', 'TC', 'TH', 'TW', |
|
237 |
'UA', 'UM', 'US', 'VE', 'VI', 'VG', 'VN', 'ZA', |
|
238 |
); |
|
458 | 239 |
if (in_array($address['country'], $countries_postal_code_after_locality)) { |
459 | 240 |
// Take the widget out of the array. |
460 | 241 |
$postal_code_widget = $format['locality_block']['postal_code']; |
... | ... | |
470 | 251 |
unset($format['locality_block'][$first_child]['#prefix']); |
471 | 252 |
} |
472 | 253 |
|
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 | 254 |
if ($context['mode'] == 'form') { |
512 | 255 |
// Provide a wrapper ID for AJAX replacement based on country selection. |
513 | 256 |
if (!isset($format['#wrapper_id'])) { |
... | ... | |
515 | 258 |
$format['#prefix'] = '<div id="' . $format['#wrapper_id'] . '">'; |
516 | 259 |
$format['#suffix'] = '</div>'; |
517 | 260 |
} |
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 | 261 |
// AJAX enable it. |
528 | 262 |
$format['country']['#ajax'] = array( |
529 | 263 |
'callback' => 'addressfield_standard_widget_refresh', |
... | ... | |
533 | 267 |
// Don't validate any element when the country is changed. |
534 | 268 |
$format['country']['#limit_validation_errors'] = array(); |
535 | 269 |
|
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. |
|
270 |
// Move the country selector to the top of the form. |
|
271 |
$format['country']['#weight'] = -500; |
|
272 |
// Limit it to the countries supported by the widget. |
|
273 |
if (isset($context['field'])) { |
|
274 |
$format['country']['#options'] = _addressfield_country_options_list($context['field'], $context['instance']); |
|
275 |
} |
|
276 |
|
|
277 |
// The whole field is considered empty if the country column is empty. |
|
278 |
// Therefore, if the field is optional, allow the country to be optional. |
|
279 |
// The same logic applies if the field allows multiple values, in which case |
|
280 |
// only the first delta needs to have a value. |
|
281 |
if (empty($context['instance']['required']) || (isset($context['delta']) && $context['delta'] > 0)) { |
|
540 | 282 |
$format['country']['#required'] = FALSE; |
541 | 283 |
$format['country']['#empty_value'] = ''; |
284 |
// Hide all other fields until the country is selected. |
|
285 |
if (empty($address['country'])) { |
|
286 |
$format['street_block']['#access'] = FALSE; |
|
287 |
$format['locality_block']['#access'] = FALSE; |
|
288 |
} |
|
542 | 289 |
} |
543 | 290 |
} |
544 | 291 |
} |
Formats disponibles : Unified diff
Weekly update of contrib modules