EDIT: As per a suggestion below, I tried using hook_field_presave, but couldn't access any parameters of the field. I then tried hook_field_attach_presave, but my alterations aren't being saved. My current module code is :
function module_field_attach_presave($entity_type, $entity) {
$field = $entity->field_user_location;
$locality = $field['und'][0]['locality'];
$locality = ucwords(strtolower($locality));
dpm($locality);
}
The transformation is present when Locality
prints out via dpm
, but the transformation is not saved to the field itself. Any idea why?
ORIGINAL: I'm using an AddressField field in my user profiles, but I'd like to make sure that the cities that users enter are correctly capitalized. How can I do this?
I'm assuming it's some implementation of str_replace
, but I don't know what to do with it.