You are here

function file_entity_file_insert in File Entity (fieldable files) 7.2

Same name and namespace in other branches
  1. 7.3 file_entity.file.inc \file_entity_file_insert()
  2. 7 file_entity.module \file_entity_file_insert()

Implements hook_file_insert().

File

./file_entity.file.inc, line 56
File hooks implemented by the File entity module.

Code

function file_entity_file_insert($file) {

  // Ensure field data is saved since file_save() does not in Drupal 7.
  field_attach_insert('file', $file);

  // Save file metadata.
  if (!empty($file->metadata)) {
    $query = db_insert('file_metadata')
      ->fields(array(
      'fid',
      'name',
      'value',
    ));
    foreach ($file->metadata as $name => $value) {
      $query
        ->values(array(
        'fid' => $file->fid,
        'name' => $name,
        'value' => serialize($value),
      ));
    }
    $query
      ->execute();
  }

  // Clear any related field caches.
  file_entity_invalidate_field_caches($file);
}