Fix some broken/missing settings for number fields.
[project/cck.git] / modules / content_migrate / modules / content_migrate.number.inc
CommitLineData
f7cb36f7
KS
1<?php
2/**
3 * @file content_migrate.number.inc
4 * Code to implement hook_content_migrate_field_alter, content_migrate_instance_alter() and content_migrate_data_record_alter()
5 * on behalf of the former number module, moved into a separate file for efficiency.
6 */
7
8/**
9 * Implements hook_content_migrate_field_alter().
10 *
11 * Use this to tweak the conversion of field settings
12 * from the D6 style to the D7 style for specific
13 * situations not handled by basic conversion,
14 * as when field types or settings are changed.
15 */
16function content_migrate_number_field_alter(&$field_value, $instance_value) {
f7cb36f7
KS
17 switch ($field_value['type']) {
18
19 case 'number_integer':
20 case 'number_decimal':
21 case 'number_float':
22
23 // Changed name of setting from 'decimal' to
24 // 'decimal_separator'.
25 if (isset($field_value['settings']['decimal'])) {
26 $field_value['settings']['decimal_separator'] = $field_value['settings']['decimal'];
27 unset($field_value['settings']['decimal']);
28 }
29 // Add a decimal_separator setting to floats.
30 if ($field_value['type'] == 'number_float') {
31 $field_value['settings']['decimal_separator'] = '.';
32 }
33
34 // Number fields using optionwidgets are
35 // now List fields.
36 switch ($instance_value['widget']['type']) {
37 case 'optionwidgets_buttons':
38 case 'optionwidgets_select':
d351e4a2
KS
39 if ($field_value['type'] == 'number_integer') {
40 $field_value['type'] = 'list_integer';
41 }
42 else {
43 $field_value['type'] = 'list_float';
44 }
f7cb36f7
KS
45 $field_value['module'] = 'list';
46 break;
47 case 'optionwidgets_onoff':
48 $field_value['type'] = 'list_boolean';
49 $field_value['module'] = 'list';
57a78f13 50 break;
f7cb36f7 51 }
938c86d5
KS
52
53 // The allowed values list should now be stored as an array.
54 $allowed_values = array();
55 if (!empty($field_value['settings']['allowed_values'])) {
56 $allowed_values = content_migrate_extract_allowed_values($field_value['settings']['allowed_values'], $field_value['type']);
57 }
58 $field_value['settings']['allowed_values'] = $allowed_values;
57a78f13 59 break;
f7cb36f7
KS
60 }
61
62}
63
64/**
65 * Implements hook_content_migrate_instance_alter().
57a78f13 66 *
f7cb36f7
KS
67 * Use this to tweak the conversion of instance or widget settings
68 * from the D6 style to the D7 style for specific
69 * situations not handled by basic conversion, as when
70 * formatter or widget names or settings are changed.
71 */
72function content_migrate_number_instance_alter(&$instance_value, $field_value) {
57a78f13
KS
73 switch ($field_value['module']) {
74 case 'number':
f7cb36f7
KS
75 // The number formatters and formatter settings
76 // have changed.
77 $new_type = array(
78 'unformatted' => 'number_unformatted',
f8244407 79 'default' => $field_value['type'] == 'number_integer' ? 'number_integer' : 'number_decimal',
f7cb36f7
KS
80 'us_0' => 'number_integer',
81 'us_1' => 'number_decimal',
82 'us_2' => 'number_decimal',
83 'be_0' => 'number_integer',
84 'be_1' => 'number_decimal',
85 'be_2' => 'number_decimal',
86 'fr_0' => 'number_integer',
87 'fr_1' => 'number_decimal',
88 'fr_2' => 'number_decimal',
89 );
90 $new_settings = array(
91 'default' => array(
92 'thousand_separator' => '',
93 'decimal_separator' => '.',
94 'scale' => 0,
95 'prefix_suffix' => TRUE,
96 ),
97 'us_0' => array(
98 'thousand_separator' => ',',
99 'decimal_separator' => '.',
100 'scale' => 0,
101 'prefix_suffix' => TRUE,
102 ),
103 'us_1' => array(
104 'thousand_separator' => ',',
105 'decimal_separator' => '.',
106 'scale' => 1,
107 'prefix_suffix' => TRUE,
108 ),
109 'us_2' => array(
110 'thousand_separator' => ',',
111 'decimal_separator' => '.',
112 'scale' => 2,
113 'prefix_suffix' => TRUE,
114 ),
115 'be_0' => array(
116 'thousand_separator' => '',
117 'decimal_separator' => ',',
118 'scale' => 0,
119 'prefix_suffix' => TRUE,
120 ),
121 'be_1' => array(
122 'thousand_separator' => '.',
123 'decimal_separator' => ',',
124 'scale' => 1,
125 'prefix_suffix' => TRUE,
126 ),
127 'be_2' => array(
128 'thousand_separator' => '.',
129 'decimal_separator' => ',',
130 'scale' => 2,
131 'prefix_suffix' => TRUE,
132 ),
133 'fr_0' => array(
134 'thousand_separator' => '',
135 'decimal_separator' => ', ',
136 'scale' => 0,
137 'prefix_suffix' => TRUE,
138 ),
139 'fr_1' => array(
140 'thousand_separator' => ' ',
141 'decimal_separator' => ', ',
142 'scale' => 1,
143 'prefix_suffix' => TRUE,
144 ),
145 'fr_2' => array(
146 'thousand_separator' => ' ',
147 'decimal_separator' => ', ',
148 'scale' => 2,
149 'prefix_suffix' => TRUE,
57a78f13 150 ),
f7cb36f7
KS
151 );
152 foreach ($instance_value['display'] as $context => $settings) {
56b496ff
KS
153 if (array_key_exists($settings['type'], $new_type)) {
154 $instance_value['display'][$context]['type'] = $new_type[$settings['type']];
155 $instance_value['display'][$context]['settings'] = $new_settings[$settings['type']];
156 }
f7cb36f7 157 }
f8244407
KS
158
159 // Min, max, prefix, and suffix moved to instance settings.
160 $instance_value['settings']['min'] = $field_value['settings']['min'];
161 $instance_value['settings']['max'] = $field_value['settings']['max'];
162 $instance_value['settings']['prefix'] = $field_value['settings']['prefix'];
163 $instance_value['settings']['suffix'] = $field_value['settings']['suffix'];
f7cb36f7
KS
164 break;
165 }
f7cb36f7 166}