Skip to content

Instantly share code, notes, and snippets.

@aschanMarcus
Created September 22, 2014 07:26
Show Gist options
  • Select an option

  • Save aschanMarcus/1388e83f9c9d740d9f86 to your computer and use it in GitHub Desktop.

Select an option

Save aschanMarcus/1388e83f9c9d740d9f86 to your computer and use it in GitHub Desktop.
<?php
$query = db_select('node', 'n');
$nids = $query
->fields('n')
->condition('type', 'fitspirator')
->execute()
->fetchCol();
$nodes = node_load_multiple($nids);
foreach ($nodes as $node) {
$location = get_the_fucking_location('node', $node);
field_attach_update('node', $location);
}
function get_the_fucking_location($entity_type, $entity) {
// Loop over any geofield using our geocode widget
$entity_info = entity_get_info($entity_type);
$bundle_name = empty($entity_info['entity keys']['bundle']) ? $entity_type : $entity->{$entity_info['entity keys']['bundle']};
foreach (field_info_instances($entity_type, $bundle_name) as $field_instance) {
if ($field_instance['widget']['type'] === 'geocoder') {
if (($field_value = geocoder_widget_get_field_value($entity_type, $field_instance, $entity)) !== FALSE) {
$entity->{$field_instance['field_name']} = $field_value;
}
else {
$entity->{$field_instance['field_name']} = array();
}
}
}
return $entity;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment