You are here

function designkit_upload_delete in DesignKit 7

Same name and namespace in other branches
  1. 6 designkit.admin.inc \designkit_upload_delete()

Element validator for image delete. Handles file delete and value setting tasks all at once.

1 string reference to 'designkit_upload_delete'
_designkit_form_alter in ./designkit.admin.inc
Implementation of hook_form_alter() for spaces_features_form, system_theme_settings.

File

./designkit.admin.inc, line 155

Code

function designkit_upload_delete($element, &$form_state) {
  $name = end($element['#parents']);
  if (isset($form_state['values']['designkit_image'][$name][$name])) {

    // Delete the old image.
    if (!empty($form_state['values']['designkit_image'][$name]['delete'])) {
      $old_file = $form_state['values']['designkit_image'][$name][$name];
      if (file_exists($old_file->uri)) {
        file_delete($old_file);
        image_path_flush($old_file->uri);
      }
      unset($form_state['values']['designkit_image'][$name]);
    }
    else {
      $form_state['values']['designkit_image'][$name] = $form_state['values']['designkit_image'][$name][$name]->fid;
    }
  }
}