1 file.entity.inc | protected FileStorageController::preSave(EntityInterface $entity) |
Overrides EntityDatabaseStorageController::presave().
Parameters
File $entity: The file entity about to be saved.
Overrides EntityDatabaseStorageController::preSave
File
- core/
modules/ file/ file.entity.inc, line 287 - Entity controller and class for files.
Class
- FileStorageController
- File storage controller for files.
Code
protected function preSave(EntityInterface $entity) {
$entity->timestamp = REQUEST_TIME;
$entity->filesize = filesize($entity->uri);
if (!isset($entity->langcode)) {
// Default the file's language code to none, because files are language
// neutral more often than language dependent.
$entity->langcode = LANGUAGE_NONE;
}
// The file type is used as a bundle key, and therefore, must not be NULL.
// It defaults to FILE_TYPE_NONE when loaded via file_load(), but in case
// file_save() is called on a new file object, default it here too.
if (!isset($entity->type)) {
$entity->type = FILE_TYPE_NONE;
}
// If the file isn't already assigned a real type, determine what type should
// be assigned to it.
if ($entity->type === FILE_TYPE_NONE) {
$type = file_get_type($entity);
if (isset($type)) {
$entity->type = $type;
}
}
}