Fragmented Thought

Drupal Migration from Location to Address Field Mapping

By

Published:

Lance Gliser

Heads up! This content is more than six months old. Take some time to verify everything still works as expected.

With Location module quickly becoming obsolete, replaced by the dedicated separate modules: addressfield, geofield, and geocoder, it's handy to have a copy paste mapping to translate the data. Here's a field map from location to addressfield format for you.

$node = node_load(###); $node->field_address = array(); if( !empty($node->locations) && is_array($node->locations) ){ foreach($node->locations as $delta => $location){ $node->field_address[$node->language][0] = array( 'country' => strtoupper($location['country']), 'administrative_area' => strtoupper($location['province']), 'sub_administrative_area' => NULL, 'locality' => $location['city'], 'dependent_locality' => NULL, 'postal_code' => $location['postal_code'], 'thoroughfare' => $location['street'], 'premise' => !empty($location['additional'])? $location['additional'] : NULL, 'sub_premise' => NULL, 'organisation_name' => $node->title, 'name_line' => NULL, 'first_name' => NULL, 'last_name' => NULL, 'data' => NULL, ); } }