function File::preCreate
Same name in other branches
- 9 core/modules/file/src/Entity/File.php \Drupal\file\Entity\File::preCreate()
- 8.9.x core/modules/file/src/Entity/File.php \Drupal\file\Entity\File::preCreate()
- 10 core/modules/file/src/Entity/File.php \Drupal\file\Entity\File::preCreate()
Overrides EntityBase::preCreate
File
-
core/
modules/ file/ src/ Entity/ File.php, line 166
Class
- File
- Defines the file entity class.
Namespace
Drupal\file\EntityCode
public static function preCreate(EntityStorageInterface $storage, array &$values) {
// Automatically detect filename if not set.
if (!isset($values['filename']) && isset($values['uri'])) {
$values['filename'] = \Drupal::service('file_system')->basename($values['uri']);
}
// Automatically detect filemime if not set.
if (!isset($values['filemime']) && isset($values['uri'])) {
$values['filemime'] = \Drupal::service('file.mime_type.guesser')->guessMimeType($values['uri']);
}
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.