View source
<?php
function addressfield_field_schema() {
$columns = array(
'country' => array(
'description' => 'Two letter ISO country code of this address.',
'type' => 'varchar',
'length' => 2,
'not null' => FALSE,
'default' => '',
),
'administrative_area' => array(
'description' => 'The administrative area of this address. (i.e. State/Province)',
'type' => 'varchar',
'length' => 255,
'default' => '',
'not null' => FALSE,
),
'sub_administrative_area' => array(
'description' => 'The sub administrative area of this address.',
'type' => 'varchar',
'length' => 255,
'default' => '',
'not null' => FALSE,
),
'locality' => array(
'description' => 'The locality of this address. (i.e. City)',
'type' => 'varchar',
'length' => 255,
'default' => '',
'not null' => FALSE,
),
'dependent_locality' => array(
'description' => 'The dependent locality of this address.',
'type' => 'varchar',
'length' => 255,
'default' => '',
'not null' => FALSE,
),
'postal_code' => array(
'description' => 'The postal code of this address.',
'type' => 'varchar',
'length' => 255,
'default' => '',
'not null' => FALSE,
),
'thoroughfare' => array(
'description' => 'The thoroughfare of this address. (i.e. Street address)',
'type' => 'varchar',
'length' => 255,
'default' => '',
'not null' => FALSE,
),
'premise' => array(
'description' => 'The premise of this address. (i.e. Apartment / Suite number)',
'type' => 'varchar',
'length' => 255,
'default' => '',
'not null' => FALSE,
),
'sub_premise' => array(
'description' => 'The sub_premise of this address.',
'type' => 'varchar',
'length' => 255,
'default' => '',
'not null' => FALSE,
),
'organisation_name' => array(
'description' => 'Contents of a primary OrganisationName element in the xNL XML.',
'type' => 'varchar',
'length' => 255,
'not null' => FALSE,
'default' => '',
),
'name_line' => array(
'description' => 'Contents of a primary NameLine element in the xNL XML.',
'type' => 'varchar',
'length' => 255,
'not null' => FALSE,
'default' => '',
),
'first_name' => array(
'description' => 'Contents of the FirstName element of a primary PersonName element in the xNL XML.',
'type' => 'varchar',
'length' => 255,
'not null' => FALSE,
'default' => '',
),
'last_name' => array(
'description' => 'Contents of the LastName element of a primary PersonName element in the xNL XML.',
'type' => 'varchar',
'length' => 255,
'not null' => FALSE,
'default' => '',
),
'data' => array(
'description' => 'Additional data for this address.',
'type' => 'text',
'size' => 'big',
'not null' => FALSE,
'serialize' => TRUE,
),
);
return array(
'columns' => $columns,
);
}
function addressfield_update_7000() {
if (!module_enable(array(
'ctools',
))) {
throw new Exception('This version of addressfield requires ctools, but it could not be enabled.');
}
$address_fields = array();
foreach (field_info_fields() as $field_name => $field_info) {
if ($field_info['type'] == 'addressfield') {
$address_fields[$field_name] = $field_name;
}
}
foreach (field_info_instances() as $entity_type => $bundles) {
foreach ($bundles as $bundle_name => $instances) {
foreach (array_intersect_key($instances, $address_fields) as $field_name => $instance) {
$widget_settings =& $instance['widget']['settings'];
if ($instance['widget']['type'] == 'addressfield_standard') {
$format_handlers = array(
'address',
);
if (in_array($widget_settings['name_format'], array(
'name_line_organisation',
'first_last_organisation',
))) {
$format_handlers[] = 'organisation';
}
if (in_array($widget_settings['name_format'], array(
'name_line',
'name_line_organisation',
))) {
$format_handlers[] = 'name-oneline';
}
else {
$format_handlers[] = 'name-full';
}
unset($widget_settings['name_format']);
$widget_settings['format_handlers'] = $format_handlers;
}
foreach ($instance['display'] as $view_mode => &$view_mode_info) {
$display_settings =& $view_mode_info['settings'];
if ($view_mode_info['type'] == 'addressfield_default') {
if (isset($widget_settings['format_handlers'])) {
$display_settings['use_widget_handlers'] = 1;
}
else {
$display_settings['use_widget_handlers'] = 0;
$display_settings['format_handlers'] = array(
'address',
'name-oneline',
);
}
}
else {
if ($view_mode_info['type'] == 'addressfield_name') {
$view_mode_info['type'] = 'addressfield_default';
$display_settings['use_widget_handlers'] = 0;
$display_settings['format_handlers'] = isset($widget_settings['format_handlers']) ? $widget_settings['format_handlers'] : array(
'address',
'name-oneline',
);
if (empty($display_settings['organisation'])) {
$display_settings['format_handlers'] = array_diff($display_settings['format_handlers'], array(
'organisation',
));
}
unset($display_settings['organisation']);
}
}
}
field_update_instance($instance);
}
}
}
}
function addressfield_update_7001() {
$address_fields = array();
foreach (field_info_fields() as $field_name => $field_info) {
if ($field_info['type'] == 'addressfield') {
$address_fields[$field_name] = $field_name;
}
}
foreach (field_info_instances() as $entity_type => $bundles) {
foreach ($bundles as $bundle_name => $instances) {
foreach (array_intersect_key($instances, $address_fields) as $field_name => $instance) {
$default_country = '';
if (!empty($instance['required']) && !empty($instance['default_value'])) {
$default_country = $instance['default_value'][0]['country'];
}
$instance['widget']['settings']['default_country'] = $default_country;
unset($instance['default_value']);
field_update_instance($instance);
}
}
}
}