You are here

function number_content_migrate_field_alter in Content Construction Kit (CCK) 7.3

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.

File

modules/content_migrate/modules/content_migrate.number.inc, line 15
content_migrate.number.inc Code to implement Content Migrate hooks on behalf of the Number module.

Code

function number_content_migrate_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':
          if ($field_value['type'] == 'number_integer') {
            $field_value['messages'][] = t("Changed field type: The '@field' field uses a '@widget' widget. The field type will be changed from '@type' to 'list_integer'.", array(
              '@type' => $field_value['type'],
              '@field' => $field_value['field_name'],
              '@widget' => $instance_value['widget']['type'],
            ));
            $field_value['type'] = 'list_integer';
          }
          else {
            $field_value['messages'][] = t("Changed field type: The '@field' field uses a '@widget' widget. The field type will be changed from '@type' to 'list_float'.", array(
              '@type' => $field_value['type'],
              '@field' => $field_value['field_name'],
              '@widget' => $instance_value['widget']['type'],
            ));
            $field_value['type'] = 'list_float';
          }
          $field_value['module'] = 'list';
          break;
        case 'optionwidgets_onoff':
          $field_value['messages'][] = t("Changed field type: The '@field' field uses a '@widget' widget. The field type will be changed from '@type' to 'list_boolean'.", array(
            '@type' => $field_value['type'],
            '@field' => $field_value['field_name'],
            '@widget' => $instance_value['widget']['type'],
          ));
          $field_value['type'] = 'list_boolean';
          $field_value['module'] = 'list';
          break;
      }

      // The allowed values list should now be stored as an array.
      $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;
  }
}