Newer
Older
Karen Stevenson
committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
<?php
/**
* @file content_migrate.number.inc
* Code to implement hook_content_migrate_field_alter, content_migrate_instance_alter() and content_migrate_data_record_alter()
* on behalf of the former number module, moved into a separate file for efficiency.
*/
/**
* Implements hook_content_migrate_field_alter().
*
* Use this to tweak the conversion of field settings
* from the D6 style to the D7 style for specific
* situations not handled by basic conversion,
* as when field types or settings are changed.
*/
function content_migrate_number_field_alter(&$field_value, $instance_value) {
switch ($field_value['type']) {
case 'number_integer':
case 'number_decimal':
case 'number_float':
// Changed name of setting from 'decimal' to
// 'decimal_separator'.
if (isset($field_value['settings']['decimal'])) {
$field_value['settings']['decimal_separator'] = $field_value['settings']['decimal'];
unset($field_value['settings']['decimal']);
}
// Add a decimal_separator setting to floats.
if ($field_value['type'] == 'number_float') {
$field_value['settings']['decimal_separator'] = '.';
}
// Number fields using optionwidgets are
// now List fields.
switch ($instance_value['widget']['type']) {
case 'optionwidgets_buttons':
case 'optionwidgets_select':
Karen Stevenson
committed
if ($field_value['type'] == 'number_integer') {
$field_value['type'] = 'list_integer';
}
else {
$field_value['type'] = 'list_float';
}
Karen Stevenson
committed
$field_value['module'] = 'list';
break;
case 'optionwidgets_onoff':
$field_value['type'] = 'list_boolean';
$field_value['module'] = 'list';
Karen Stevenson
committed
break;
Karen Stevenson
committed
}
Karen Stevenson
committed
break;
Karen Stevenson
committed
}
}
/**
* Implements hook_content_migrate_instance_alter().
Karen Stevenson
committed
*
Karen Stevenson
committed
* Use this to tweak the conversion of instance or widget settings
* from the D6 style to the D7 style for specific
* situations not handled by basic conversion, as when
* formatter or widget names or settings are changed.
*/
function content_migrate_number_instance_alter(&$instance_value, $field_value) {
Karen Stevenson
committed
switch ($field_value['module']) {
case 'number':
Karen Stevenson
committed
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
// The number formatters and formatter settings
// have changed.
$new_type = array(
'unformatted' => 'number_unformatted',
'default' => 'number_decimal',
'us_0' => 'number_integer',
'us_1' => 'number_decimal',
'us_2' => 'number_decimal',
'be_0' => 'number_integer',
'be_1' => 'number_decimal',
'be_2' => 'number_decimal',
'fr_0' => 'number_integer',
'fr_1' => 'number_decimal',
'fr_2' => 'number_decimal',
);
$new_settings = array(
'default' => array(
'thousand_separator' => '',
'decimal_separator' => '.',
'scale' => 0,
'prefix_suffix' => TRUE,
),
'us_0' => array(
'thousand_separator' => ',',
'decimal_separator' => '.',
'scale' => 0,
'prefix_suffix' => TRUE,
),
'us_1' => array(
'thousand_separator' => ',',
'decimal_separator' => '.',
'scale' => 1,
'prefix_suffix' => TRUE,
),
'us_2' => array(
'thousand_separator' => ',',
'decimal_separator' => '.',
'scale' => 2,
'prefix_suffix' => TRUE,
),
'be_0' => array(
'thousand_separator' => '',
'decimal_separator' => ',',
'scale' => 0,
'prefix_suffix' => TRUE,
),
'be_1' => array(
'thousand_separator' => '.',
'decimal_separator' => ',',
'scale' => 1,
'prefix_suffix' => TRUE,
),
'be_2' => array(
'thousand_separator' => '.',
'decimal_separator' => ',',
'scale' => 2,
'prefix_suffix' => TRUE,
),
'fr_0' => array(
'thousand_separator' => '',
'decimal_separator' => ', ',
'scale' => 0,
'prefix_suffix' => TRUE,
),
'fr_1' => array(
'thousand_separator' => ' ',
'decimal_separator' => ', ',
'scale' => 1,
'prefix_suffix' => TRUE,
),
'fr_2' => array(
'thousand_separator' => ' ',
'decimal_separator' => ', ',
'scale' => 2,
'prefix_suffix' => TRUE,
Karen Stevenson
committed
),
Karen Stevenson
committed
);
foreach ($instance_value['display'] as $context => $settings) {
Karen Stevenson
committed
$instance_value['display'][$context]['type'] = $new_type[$settings['type']];
$instance_value['display'][$context]['settings'] = $new_settings[$settings['type']];
Karen Stevenson
committed
}
break;
}
Karen Stevenson
committed