1
|
<?php
|
2
|
|
3
|
/**
|
4
|
* Implements hook_field_schema()
|
5
|
*/
|
6
|
function addressfield_field_schema() {
|
7
|
$columns = array(
|
8
|
'country' => array(
|
9
|
'description' => 'Two letter ISO country code of this address.',
|
10
|
'type' => 'varchar',
|
11
|
'length' => 2,
|
12
|
'not null' => FALSE,
|
13
|
'default' => '',
|
14
|
),
|
15
|
'administrative_area' => array(
|
16
|
'description' => 'The administrative area of this address. (i.e. State/Province)',
|
17
|
'type' => 'varchar',
|
18
|
'length' => 255,
|
19
|
'default' => '',
|
20
|
'not null' => FALSE,
|
21
|
),
|
22
|
'sub_administrative_area' => array(
|
23
|
'description' => 'The sub administrative area of this address.',
|
24
|
'type' => 'varchar',
|
25
|
'length' => 255,
|
26
|
'default' => '',
|
27
|
'not null' => FALSE,
|
28
|
),
|
29
|
'locality' => array(
|
30
|
'description' => 'The locality of this address. (i.e. City)',
|
31
|
'type' => 'varchar',
|
32
|
'length' => 255,
|
33
|
'default' => '',
|
34
|
'not null' => FALSE,
|
35
|
),
|
36
|
'dependent_locality' => array(
|
37
|
'description' => 'The dependent locality of this address.',
|
38
|
'type' => 'varchar',
|
39
|
'length' => 255,
|
40
|
'default' => '',
|
41
|
'not null' => FALSE,
|
42
|
),
|
43
|
'postal_code' => array(
|
44
|
'description' => 'The postal code of this address.',
|
45
|
'type' => 'varchar',
|
46
|
'length' => 255,
|
47
|
'default' => '',
|
48
|
'not null' => FALSE,
|
49
|
),
|
50
|
'thoroughfare' => array(
|
51
|
'description' => 'The thoroughfare of this address. (i.e. Street address)',
|
52
|
'type' => 'varchar',
|
53
|
'length' => 255,
|
54
|
'default' => '',
|
55
|
'not null' => FALSE,
|
56
|
),
|
57
|
'premise' => array(
|
58
|
'description' => 'The premise of this address. (i.e. Apartment / Suite number)',
|
59
|
'type' => 'varchar',
|
60
|
'length' => 255,
|
61
|
'default' => '',
|
62
|
'not null' => FALSE,
|
63
|
),
|
64
|
'sub_premise' => array(
|
65
|
'description' => 'The sub_premise of this address.',
|
66
|
'type' => 'varchar',
|
67
|
'length' => 255,
|
68
|
'default' => '',
|
69
|
'not null' => FALSE,
|
70
|
),
|
71
|
'organisation_name' => array(
|
72
|
'description' => 'Contents of a primary OrganisationName element in the xNL XML.',
|
73
|
'type' => 'varchar',
|
74
|
'length' => 255,
|
75
|
'not null' => FALSE,
|
76
|
'default' => '',
|
77
|
),
|
78
|
'name_line' => array(
|
79
|
'description' => 'Contents of a primary NameLine element in the xNL XML.',
|
80
|
'type' => 'varchar',
|
81
|
'length' => 255,
|
82
|
'not null' => FALSE,
|
83
|
'default' => '',
|
84
|
),
|
85
|
'first_name' => array(
|
86
|
'description' => 'Contents of the FirstName element of a primary PersonName element in the xNL XML.',
|
87
|
'type' => 'varchar',
|
88
|
'length' => 255,
|
89
|
'not null' => FALSE,
|
90
|
'default' => '',
|
91
|
),
|
92
|
'last_name' => array(
|
93
|
'description' => 'Contents of the LastName element of a primary PersonName element in the xNL XML.',
|
94
|
'type' => 'varchar',
|
95
|
'length' => 255,
|
96
|
'not null' => FALSE,
|
97
|
'default' => '',
|
98
|
),
|
99
|
'data' => array(
|
100
|
'description' => 'Additional data for this address.',
|
101
|
'type' => 'text',
|
102
|
'size' => 'big',
|
103
|
'not null' => FALSE,
|
104
|
'serialize' => TRUE,
|
105
|
),
|
106
|
);
|
107
|
|
108
|
return array(
|
109
|
'columns' => $columns,
|
110
|
// TODO Add indexes.
|
111
|
);
|
112
|
}
|
113
|
|
114
|
/**
|
115
|
* Update the field configuration to the new plugin structure.
|
116
|
*/
|
117
|
function addressfield_update_7000() {
|
118
|
// Enable ctools.
|
119
|
if (!module_enable(array('ctools'))) {
|
120
|
throw new Exception('This version of addressfield requires ctools, but it could not be enabled.');
|
121
|
}
|
122
|
|
123
|
// Get the list of fields of type 'addressfield'.
|
124
|
$address_fields = array();
|
125
|
foreach (field_info_fields() as $field_name => $field_info) {
|
126
|
if ($field_info['type'] == 'addressfield') {
|
127
|
$address_fields[$field_name] = $field_name;
|
128
|
}
|
129
|
}
|
130
|
|
131
|
foreach (field_info_instances() as $entity_type => $bundles) {
|
132
|
foreach ($bundles as $bundle_name => $instances) {
|
133
|
foreach (array_intersect_key($instances, $address_fields) as $field_name => $instance) {
|
134
|
$widget_settings = &$instance['widget']['settings'];
|
135
|
|
136
|
if ($instance['widget']['type'] == 'addressfield_standard') {
|
137
|
// Default to use the country-based address widget.
|
138
|
$format_handlers = array('address');
|
139
|
|
140
|
// Map the old 'name_format' setting to the name and organization widgets.
|
141
|
if (in_array($widget_settings['name_format'], array('name_line_organisation', 'first_last_organisation'))) {
|
142
|
$format_handlers[] = 'organisation';
|
143
|
}
|
144
|
if (in_array($widget_settings['name_format'], array('name_line', 'name_line_organisation'))) {
|
145
|
$format_handlers[] = 'name-oneline';
|
146
|
}
|
147
|
else {
|
148
|
$format_handlers[] = 'name-full';
|
149
|
}
|
150
|
unset($widget_settings['name_format']);
|
151
|
$widget_settings['format_handlers'] = $format_handlers;
|
152
|
}
|
153
|
|
154
|
// Update displays.
|
155
|
foreach ($instance['display'] as $view_mode => &$view_mode_info) {
|
156
|
$display_settings = &$view_mode_info['settings'];
|
157
|
|
158
|
if ($view_mode_info['type'] == 'addressfield_default') {
|
159
|
if (isset($widget_settings['format_handlers'])) {
|
160
|
$display_settings['use_widget_handlers'] = 1;
|
161
|
}
|
162
|
else {
|
163
|
// If the widget is non-standard, just use a sane default.
|
164
|
$display_settings['use_widget_handlers'] = 0;
|
165
|
$display_settings['format_handlers'] = array('address', 'name-oneline');
|
166
|
}
|
167
|
}
|
168
|
else if ($view_mode_info['type'] == 'addressfield_name') {
|
169
|
// Migrate the 'addressfield_name' formatter to the new framework.
|
170
|
$view_mode_info['type'] = 'addressfield_default';
|
171
|
// Start from the widget configuration.
|
172
|
$display_settings['use_widget_handlers'] = 0;
|
173
|
$display_settings['format_handlers'] = isset($widget_settings['format_handlers']) ? $widget_settings['format_handlers'] : array('address', 'name-oneline');
|
174
|
|
175
|
if (empty($display_settings['organisation'])) {
|
176
|
$display_settings['format_handlers'] = array_diff( $display_settings['format_handlers'], array('organisation'));
|
177
|
}
|
178
|
unset($display_settings['organisation']);
|
179
|
}
|
180
|
}
|
181
|
|
182
|
field_update_instance($instance);
|
183
|
}
|
184
|
}
|
185
|
}
|
186
|
}
|