You are here

function location_cck_field_delete in Location 7.3

Same name and namespace in other branches
  1. 7.5 contrib/location_cck/location_cck.module \location_cck_field_delete()

Implement hook_field_delete().

File

contrib/location_cck/location_cck.module, line 234
Defines location field type.

Code

function location_cck_field_delete($entity_type, $entity, $field, $instance, $langcode, &$items) {
  if ($entity_type == 'node') {

    // @TODO: Fix this properly.
    // Use the CCK storage to figure out the vids that need to be deleted,
    // and clean up all the applicable references.
    // $db_info = content_database_info($field);
    $result = db_query('SELECT vid FROM {node_revision} WHERE nid = :nid', array(
      ':nid' => $entity->nid,
    ));
    foreach ($result as $row) {
      $genid = 'cck:' . $field['field_name'] . ':' . $row->vid;
      $locs = array();
      location_save_locations($locs, array(
        'genid' => $genid,
      ));
    }
  }
  elseif ($entity_type == 'user') {
    $genid = 'cck:' . $field['field_name'] . ':' . $entity->uid;
    $locs = array();
    location_save_locations($locs, array(
      'genid' => $genid,
    ));
  }
  else {
    list($id, $vid, $bundle) = entity_extract_ids($entity_type, $entity);
    $genid = 'field:' . $field['field_name'] . ':' . $entity_type . ':' . $id;
    $locs = array();
    location_save_locations($locs, array(
      'genid' => $genid,
    ));
  }
}