Issue #1092840 by dww, Allowed values for list_number and list_boolean not converted...
[project/cck.git] / modules / content_migrate / modules / content_migrate.text.inc
1 <?php
2 /**
3 * @file content_migrate.text.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 text 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 */
16 function content_migrate_text_field_alter(&$field_value, $instance_value) {
17 switch ($field_value['type']) {
18 case 'text':
19
20 // Text fields are translatable.
21 $field_value['translatable'] = TRUE;
22
23 // The max_length field can no longer be empty
24 // or it will create a SQL error.
25 if (empty($field_value['settings']['max_length'])) {
26 $field_value['settings']['max_length'] = 255;
27 }
28
29 // Text fields using optionwidgets are
30 // now List fields.
31 switch ($instance_value['widget']['type']) {
32 case 'optionwidgets_buttons':
33 case 'optionwidgets_select':
34 $field_value['type'] = 'list_text';
35 $field_value['module'] = 'list';
36 break;
37
38 case 'optionwidgets_onoff':
39 $field_value['type'] = 'list_boolean';
40 $field_value['module'] = 'list';
41 break;
42
43 case 'text_textarea':
44 $field_value['type'] = 'text_long';
45 unset($field_value['settings']['max_length']);
46 break;
47
48 }
49
50 // The allowed values list should now be stored as an array.
51 switch ($field_value['type']) {
52 case 'list_text':
53 case 'list_boolean':
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;
59 break;
60
61 }
62
63 break;
64 }
65
66 }
67
68 /**
69 * Implements hook_content_migrate_instance_alter().
70 *
71 * Use this to tweak the conversion of instance or widget settings
72 * from the D6 style to the D7 style for specific
73 * situations not handled by basic conversion, as when
74 * formatter or widget names or settings are changed.
75 */
76 function content_migrate_text_instance_alter(&$instance_value, $field_value) {
77 switch ($field_value['module']) {
78 case 'text':
79 // The formatter names changed, all are prefixed
80 // with 'text_'.
81 foreach ($instance_value['display'] as $context => $settings) {
82 $instance_value['display'][$context]['type'] = 'text_'. $settings['type'];
83 }
84 break;
85 }
86
87 }