Révision 9d13637e
Ajouté par Assos Assos il y a plus de 9 ans
drupal7/sites/all/modules/addressfield/addressfield.api.php | ||
---|---|---|
29 | 29 |
// No example. |
30 | 30 |
} |
31 | 31 |
|
32 |
/** |
|
33 |
* Allows modules to alter the default values for an address field. |
|
34 |
* |
|
35 |
* @param $default_values |
|
36 |
* The array of default values. The country is populated from the |
|
37 |
* 'default_country' widget setting. |
|
38 |
* @param $context |
|
39 |
* An array with the following keys: |
|
40 |
* - field: The field array. |
|
41 |
* - instance: The instance array. |
|
42 |
* - address: The current address values. Allows for per-country defaults. |
|
43 |
*/ |
|
44 |
function hook_addressfield_default_values_alter(&$default_values, $context) { |
|
45 |
// If no other default country was provided, set it to France. |
|
46 |
// Note: you might want to check $context['instance']['required'] and |
|
47 |
// skip setting the default country if the field is optional. |
|
48 |
if (empty($default_values['country'])) { |
|
49 |
$default_values['country'] = 'FR'; |
|
50 |
} |
|
51 |
|
|
52 |
// Determine the country for which other defaults should be provided. |
|
53 |
$selected_country = $default_values['country']; |
|
54 |
if (isset($context['address']['country'])) { |
|
55 |
$selected_country = $context['address']['country']; |
|
56 |
} |
|
57 |
|
|
58 |
// Add defaults for the US. |
|
59 |
if ($selected_country == 'US') { |
|
60 |
$default_values['locality'] = 'New York'; |
|
61 |
$default_values['administrative_area'] = 'NY'; |
|
62 |
} |
|
63 |
} |
|
64 |
|
|
32 | 65 |
/** |
33 | 66 |
* Allows modules to alter the predefined address formats. |
34 | 67 |
* |
Formats disponibles : Unified diff
Weekly update of contrib modules