You are here

function imagefield_crop_field_delete in Imagefield Crop 7.3

Same name and namespace in other branches
  1. 7.2 imagefield_crop.module \imagefield_crop_field_delete()

Implements hook_field_delete().

File

./imagefield_crop.module, line 232

Code

function imagefield_crop_field_delete($entity_type, $entity, $field, $instance, $langcode, &$items) {
  list($id, $vid, $bundle) = entity_extract_ids($entity_type, $entity);
  $entity_w = entity_metadata_wrapper($entity_type, $entity);
  $key = $entity_w
    ->entityKey('revision') ? $entity_w
    ->entityKey('revision') : $entity_w
    ->entityKey('id');

  // Delete all file usages within this entity.
  foreach ($items as $item) {
    $variants = imagefield_crop_variants_load_multiple($item['fid'], $entity->{$key});
    foreach ($variants as $pid => $variant) {
      $file = file_load($variant->fid);
      file_usage_delete($file, 'imagefield_crop', NULL, NULL, 0);
      file_delete($file);
    }
    $orig_file = file_load($item['fid']);
    file_field_delete_file($orig_file, $field, $entity_type, $id, 0);
    imagefield_crop_variants_delete_multiple(array(), $item['fid'], $vid);
  }
}