function _addressfield_autocomplete_widget_transform in Addressfield Autocomplete 7
Addressfield autocomplete transform.
Transforms data into the structure accepted by addressfield.
1 string reference to '_addressfield_autocomplete_widget_transform'
File
- ./
addressfield_autocomplete.module, line 545 - The Addressfield Autocomplete module code.
Code
function _addressfield_autocomplete_widget_transform($element, &$form_state, $form) {
$parents = $element['#parents'];
$values = drupal_array_get_nested_value($form_state['values'], $parents);
$data = $address = array();
if (!empty($values['autocomplete'])) {
$data['latitude'] = $values['widget']['latitude'];
$data['longitude'] = $values['widget']['longitude'];
$data['zoom'] = $values['widget']['zoom'];
$data['formatted_address'] = $values['autocomplete'];
foreach (array(
'latitude',
'longitude',
'zoom',
) as $key) {
unset($values['widget'][$key]);
}
$address = $values['widget'];
$address['data'] = serialize($data);
}
array_pop($parents);
drupal_array_set_nested_value($form_state['values'], $parents, $address);
/*
* From addressfield 7.x-1.0-rc1 we also need to set the input to the value
* of the widget. Otherwise the form does not appear.
*/
drupal_array_set_nested_value($form_state['input'], $parents, $address);
}