function File::preSave

Same name in other branches
  1. 8.9.x core/modules/file/src/Entity/File.php \Drupal\file\Entity\File::preSave()
  2. 10 core/modules/file/src/Entity/File.php \Drupal\file\Entity\File::preSave()
  3. 11.x core/modules/file/src/Entity/File.php \Drupal\file\Entity\File::preSave()

Overrides ContentEntityBase::preSave

File

core/modules/file/src/Entity/File.php, line 177

Class

File
Defines the file entity class.

Namespace

Drupal\file\Entity

Code

public function preSave(EntityStorageInterface $storage) {
    parent::preSave($storage);
    // The file itself might not exist or be available right now.
    $uri = $this->getFileUri();
    $size = @filesize($uri);
    // Set size unless there was an error.
    if ($size !== FALSE) {
        $this->setSize($size);
    }
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.