The addressfield module is required by the new Drupal Commerce module and it would be great if it was supported here. Can anyone help point me in the right direction? I might be able to tackle this myself with a bit of direction. Cheers.

Comments

mikey_p’s picture

Support would actually go into the addressfield module itself, look at the MigrationDestination plugins for the fields that come with core.

geerlingguy’s picture

Subscribe.

geerlingguy’s picture

Status: Active » Needs review

Okay, so I didn't do this in the most flexible way (if I get time later, I'll try to make an inc for Addressfield, but I don't know when that'll be ;-)... but here goes:

I made (with the help of joelstein) a generic field handler that works for a few different types of fields out of the box, and put that inside mymodule.fields.inc:

/**
 * Boring, default, pseudo field handler.
 */
class JeffFieldHandler extends MigrateFieldHandler {

  public function __construct() {
    $this->registerTypes(array('link_field', 'phone_number', 'addressfield'));
  }

  public function prepare($entity, array $field_info, array $instance, array $values) {
    $language = $this->getFieldLanguage($entity, $field_info, array());
    $return[$language] = $values;
    return $return;
  }

}

Then, in my Migration class (in my case, for a user profile using profile2), I used the following bit of code in prepareRow to prepare the address field (which I map from my the below-generated 'address' to my profile's 'field_profile_address':

    // Prepare Address Field.
    if (!empty($row->mem_address)) {
      $row->address = array(array(
        'country' => 'US',
        'administrative_area' => $row->mem_state,
        'locality' => $row->mem_city,
        'postal_code' => $row->mem_zip,
        'thoroughfare' => $row->mem_address,
        'premise' => '', // Address line 2 (empty in source).
      ));
    } else {
      $row->address = NULL;
    }

A lot of contrib fields are structured similarly, so the only thing you'd have to worry about is (a) adding the field's key to the registerTypes function in the FieldHandler, and (b) the depth of the array you pass to this fieldhandler - for Address Fields, I have to have a nested array to account for the field delta.

lsolesen’s picture

I could help creating the addressfield.inc if someone could give some pointers on where to put it.

drewish’s picture

Version: 7.x-2.0-rc1 » 7.x-2.x-dev
StatusFileSize
new3.43 KB

Here's a handler that follows the field handler pattern used else where in migrate and migrate_extras.

mikeryan’s picture

Status: Needs review » Fixed

Committed, thanks!

drewish’s picture

Whoops, forgot to update the README. You also might want to add it to the release notes on http://drupal.org/node/1283376 #1283376: migrate_extras 7.x-2.2

drewish’s picture

Status: Fixed » Needs review
StatusFileSize
new505 bytes
mikeryan’s picture

Status: Needs review » Fixed

I've updated the README to reflect all current integrations.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.