function location_cck_field_insert in Location 7.3
Same name and namespace in other branches
- 7.5 contrib/location_cck/location_cck.module \location_cck_field_insert()
- 7.4 contrib/location_cck/location_cck.module \location_cck_field_insert()
Implement hook_field_insert().
File
- contrib/
location_cck/ location_cck.module, line 157 - Defines location field type.
Code
function location_cck_field_insert($entity_type, $entity, $field, $instance, $langcode, &$items) {
if (empty($items)) {
return;
}
$criteria = array();
// @todo refactoring, code of this function is duplicated in other places in
// this module, and could be used in one place, instead of different places.
if ($entity_type == 'node') {
// Store instances of locations by field name and vid.
$criteria = array(
'genid' => 'cck:' . $field['field_name'] . ':' . $entity->vid,
'vid' => $entity->vid,
'nid' => $entity->nid,
);
}
elseif ($entity_type == 'user') {
// Store instances of locations by field name and vid.
$criteria = array(
'genid' => 'cck:' . $field['field_name'] . ':' . $entity->uid,
'uid' => $entity->uid,
);
}
else {
list($id, $vid, $bundle) = entity_extract_ids($entity_type, $entity);
// Store instances of locations by field name and vid.
$criteria = array(
'genid' => 'field:' . $field['field_name'] . ':' . $entity_type . ':' . $id,
'vid' => $vid ? $vid : $id,
'nid' => $id,
);
}
if (!empty($criteria)) {
location_save_locations($items, $criteria);
}
}