See #626380-1: Add migrate.module support for uc_order (orders, order product details, etc) for some background...

Basically, it'd be great to be able to define various field conversion handlers. When the admin is selecting which source fields should be mapped into each destination field and providing defaults, they could select which conversion handler, if any, to apply to the source value before stuffing it into the target field.

For example, we already hard-code this in a few places for _migrate_valid_date() to convert arbitrary date strings into timestamp values if the destination field is really a timestamp int, not a full date string.

The specific example I hit with importing UberCart orders is that it wants countries and zones via its own country and zone code integers, whereas the source data is going to have country names or 3 letter country codes. In theory, #610128: Can't add external and internal tables' columns to the same view could help solve this particular case, but AFAICT, the best solution proposed in there is a mysql-specific hack...

I imagine something like hook_migrate_field_translation_handlers() to register translation handlers available to the system:

function foo_migrate_field_translation_handlers() {
  $handlers = array();
  $handlers['foo_handler_name'] = array(
    'name' => t('Name visible in the UI'),
    'callback' => 'foo_handler_callback_function_name',
    'file' => '', // optional location of the .inc file where your callback lives
  );
  ...
  return $handlers
}

More or less... ;)

Thoughts?

Thanks,
-Derek

Comments

moshe weitzman’s picture

fago was talking to me about omething like this regarding http://drupal.org/project/transformations. it went over my head, for the most part.

at a gut level, i think this is going to be useful. would be great to know which formatter logic people have used in their projects and if it makes sense to share these handlers in Contrib somehow.

dww’s picture

I had no idea the Transformations API existed. ;) But yeah, something like that, perhaps. ;)

mikeryan’s picture

Status: Active » Closed (won't fix)

Won't happen for Migrate 1, Migrate 2 has a flexible handler system to allow you to do what you will at runtime.