To migrate from Location 6.x-3.x to Addressfield 7.x-1.x in Drupal 7 you must create a custom class since the location module data is not stored in CCK. The location and location_instance tables must be manually added by implementing the query method. As of Addressfield 7.x-1.x and Migrate_d2d 7.x-2.x the address subfields (e.g., "field_address:administrative_area") are not available so the location columns must be mapped as arguments to the address field country mapping, and then hidden.
<?php
/**
* Migrate the venue content type.
*/
class VenueMigration extends DrupalNode6Migration {
public function __construct(array $arguments) {
parent::__construct($arguments);
// Map address field
$address_arguments = array(
'administrative_area'=> array('source_field'=> 'province'),
'locality'=> array('source_field'=> 'city'),
'thoroughfare'=> array('source_field'=> 'street'),
'premise'=> array('source_field'=> 'additional'),
'postal_code'=> array('source_field'=> 'postal_code'),
);
$this->addFieldMapping('field_address', 'country')
->arguments($address_arguments);
// Hide these sources because they are added as arguments
$unmapped_sources = array(
'province',
'city',
'street',
'additional',
'postal_code',
);
$this->addUnmigratedSources($unmapped_sources, t('DNM'));
}
protected function query() {
$query = parent::query();
// Join location table, which is not CCK
$query->join('location_instance', 'i', 'i.nid = n.nid AND i.vid = n.vid');
$query->join('location', 'l', 'l.lid = i.lid');
$query->fields('l', array('street', 'additional', 'city', 'province', 'postal_code', 'country'));
return $query;
}
}
?>