Migrate Location module content from Drupal 6
Last updated on
30 April 2025
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 7.x-2.5 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.
/**
* 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;
}
}
Help improve this page
Page status: Not set
You can:
You can:
- Log in, click Edit, and edit this page
- Log in, click Discuss, update the Page status value, and suggest an improvement
- Log in and create a Documentation issue with your suggestion