summaryrefslogtreecommitdiffstats
path: root/modules/content_migrate/modules/content_migrate.text.inc
blob: fe0756fe4a4c2a63ebddfc5d1d5aae929e4c8243 (plain)
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
<?php
/**
 * @file content_migrate.text.inc
 * Code to implement hook_content_migrate_field_alter, content_migrate_instance_alter() and content_migrate_data_record_alter()
 * on behalf of the former text 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_text_field_alter(&$field_value, $instance_value) {
  switch ($field_value['type']) {
    case 'text':

      // Text fields are translatable.      
      $field_value['translatable'] = TRUE;

      // The max_length field can no longer be empty 
      // or it will create a SQL error.
      if (empty($field_value['settings']['max_length'])) {
        $field_value['settings']['max_length'] = 255;
      }

      // Text fields using optionwidgets are
      // now List fields.
      switch ($instance_value['widget']['type']) {
        case 'optionwidgets_buttons':
        case 'optionwidgets_select':
          $field_value['type'] = 'list_text';
          $field_value['module'] = 'list';
          break;

        case 'optionwidgets_onoff':
          $field_value['type'] = 'list_boolean';
          $field_value['module'] = 'list';
          break;

        case 'text_textarea':
          $field_value['type'] = 'text_long';
          unset($field_value['settings']['max_length']);
          break;

      }

      // The allowed values list should now be stored as an array.
      switch ($field_value['type']) {
        case 'list_text':
        case 'list_boolean':
          $allowed_values = array();
          if (!empty($field_value['settings']['allowed_values'])) {
            $allowed_values = content_migrate_extract_allowed_values($field_value['settings']['allowed_values'], $field_value['type']);
          }
          $field_value['settings']['allowed_values'] = $allowed_values;
          break;

      }

      break;
  }

}

/**
 * Implements hook_content_migrate_instance_alter().
 *
 * 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_text_instance_alter(&$instance_value, $field_value) {
  switch ($field_value['module']) {
    case 'text':
      // The formatter names changed, all are prefixed
      // with 'text_'.
      foreach ($instance_value['display'] as $context => $settings) {
        $instance_value['display'][$context]['type'] = 'text_'. $settings['type'];
      }
      break;
  }

}