You are here

function crop_file_delete in Crop API 8

Same name and namespace in other branches
  1. 8.2 crop.module \crop_file_delete()

Implements hook_ENTITY_TYPE_delete().

Deletes orphaned crops when a file is deleted.

File

./crop.module, line 187
The Crop API Drupal module.

Code

function crop_file_delete(FileInterface $file) {

  // Get all crops for the file being deleted.
  $crops = \Drupal::entityTypeManager()
    ->getStorage('crop')
    ->loadByProperties([
    'uri' => $file
      ->getFileUri(),
  ]);
  foreach ($crops as $crop) {
    $crop
      ->delete();
  }
}