You are here

function file_entity_file_presave in D7 Media 7

Implements hook_file_presave().

File

file_entity/file_entity.module, line 174
Extends Drupal file entities to be fieldable and viewable.

Code

function file_entity_file_presave($file) {

  // The file type is a bundle key, so can't be NULL. file_entity_schema_alter()
  // ensures that it isn't NULL after a file_load(). However, file_save() can be
  // called on a new file object, so we apply the default here as well.
  if (!isset($file->type)) {
    $file->type = FILE_TYPE_NONE;
  }

  // If the file doesn't already have a real type, attempt to assign it one.
  if ($file->type == FILE_TYPE_NONE && ($type = file_get_type($file))) {
    $file->type = $type;
  }
  field_attach_presave('file', $file);
}