You are here

function dynamic_banner_image_delete in Dynamic Banner 7.2

Same name and namespace in other branches
  1. 7 includes/callbacks.inc \dynamic_banner_image_delete()
  2. 8.x dynamic_banner.module \dynamic_banner_image_delete()

This function will split the csv fid variable if it needs to be split And then delete those images from the file system and their values in the db

File

./dynamic_banner.module, line 1013
Distributed under GNU GPL version 3

Code

function dynamic_banner_image_delete($fid) {
  if (strrpos($fid, ',')) {

    // Split the plain string into an array
    $all_fids = explode(',', $imgfid);

    // Load all files at once
    $all_files = file_load_multiple($all_fids);
    foreach ($all_files as $file) {
      if ($file) {

        // When a module is managing a file, it must manage the usage count.
        // Here we decrement the usage count with file_usage_delete().
        file_usage_delete($file, 'dynamic_banner', 'banner', 1);

        // The file_delete() function takes a file object and checks to see if
        // The file is being used by any other modules. If it is the delete
        // Operation is cancelled, otherwise the file is deleted.
        file_delete($file);
      }
      drupal_set_message(t('The image @image_name was removed.', array(
        '@image_name' => $file->filename,
      )));
    }
  }
  else {
    $file = $fid ? file_load($fid) : FALSE;
    if ($file) {

      // When a module is managing a file, it must manage the usage count.
      // Here we decrement the usage count with file_usage_delete().
      file_usage_delete($file, 'dynamic_banner', 'banner', 1);

      // The file_delete() function takes a file object and checks to see if
      // The file is being used by any other modules. If it is the delete
      // Operation is cancelled, otherwise the file is deleted.
      file_delete($file);
    }
    drupal_set_message(t('The image @image_name was removed.', array(
      '@image_name' => $file->filename,
    )));
  }
}