root / drupal7 / sites / all / modules / addressfield / addressfield.api.php @ fc3d89c3
1 |
<?php
|
---|---|
2 |
|
3 |
/**
|
4 |
* @file
|
5 |
* API documentation for Addressfield.
|
6 |
*/
|
7 |
|
8 |
/**
|
9 |
* Format generation callback.
|
10 |
*
|
11 |
* @param $format
|
12 |
* The address format being generated.
|
13 |
* @param $address
|
14 |
* The address this format is generated for.
|
15 |
* @param $context
|
16 |
* An associative array of context information pertaining to how the address
|
17 |
* format should be generated. If no mode is given, it will initialize to the
|
18 |
* default value. The remaining context keys should only be present when the
|
19 |
* address format is being generated for a field:
|
20 |
* - mode: either 'form' or 'render'; defaults to 'render'.
|
21 |
* - field: the field info array.
|
22 |
* - instance: the field instance array.
|
23 |
* - langcode: the langcode of the language the field is being rendered in.
|
24 |
* - delta: the delta value of the given address.
|
25 |
*
|
26 |
* @ingroup addressfield_format
|
27 |
*/
|
28 |
function CALLBACK_addressfield_format_callback(&$format, $address, $context = array()) { |
29 |
// No example.
|
30 |
} |
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 |
|
65 |
/**
|
66 |
* Allows modules to alter the predefined address formats.
|
67 |
*
|
68 |
* @param $address_formats
|
69 |
* The array of all predefined address formats.
|
70 |
*
|
71 |
* @see addressfield_get_address_format()
|
72 |
*/
|
73 |
function hook_addressfield_address_formats_alter(&$address_formats) { |
74 |
// Remove the postal_code from the list of required fields for China.
|
75 |
$address_formats['CN']['required_fields'] = array('locality', 'administrative_area'); |
76 |
} |
77 |
|
78 |
/**
|
79 |
* Allows modules to alter the predefined administrative areas.
|
80 |
*
|
81 |
* @param $administrative_areas
|
82 |
* The array of all predefined administrative areas.
|
83 |
*
|
84 |
* @see addressfield_get_administrative_areas()
|
85 |
*/
|
86 |
function hook_addressfield_administrative_areas_alter(&$administrative_areas) { |
87 |
// Alter the label of the Spanish administrative area with the iso code PM.
|
88 |
$administrative_areas['ES']['PM'] = t('Balears / Baleares'); |
89 |
|
90 |
// Add administrative areas for imaginary country XT, keyed by their
|
91 |
// imaginary ISO codes.
|
92 |
$administrative_areas['XT'] = array( |
93 |
'A' => t('Aland'), |
94 |
'B' => t('Bland'), |
95 |
); |
96 |
} |
97 |
|
98 |
/**
|
99 |
* Allows modules to add arbitrary AJAX commands to the array returned from the
|
100 |
* standard address field widget refresh.
|
101 |
*
|
102 |
* @param &$commands
|
103 |
* The array of AJAX commands used to refresh the address field widget.
|
104 |
* @param $form
|
105 |
* The rebuilt form array.
|
106 |
* @param $form_state
|
107 |
* The form state array from the form.
|
108 |
*
|
109 |
* @see addressfield_standard_widget_refresh()
|
110 |
*/
|
111 |
function hook_addressfield_standard_widget_refresh_alter(&$commands, $form, $form_state) { |
112 |
// Display an alert message.
|
113 |
$commands[] = ajax_command_alert(t('The address field widget has been updated.')); |
114 |
} |