public static function File::preCreate in Zircon Profile 8
Same name and namespace in other branches
- 8.0 core/modules/file/src/Entity/File.php \Drupal\file\Entity\File::preCreate()
Changes the values of an entity before it is created.
Load defaults for example.
Parameters
\Drupal\Core\Entity\EntityStorageInterface $storage: The entity storage object.
mixed[] $values: An array of values to set, keyed by property name. If the entity type has bundles the bundle key has to be specified.
Overrides Entity::preCreate
File
- core/
modules/ file/ src/ Entity/ File.php, line 174 - Contains \Drupal\file\Entity\File.
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_basename($values['uri']);
}
// Automatically detect filemime if not set.
if (!isset($values['filemime']) && isset($values['uri'])) {
$values['filemime'] = \Drupal::service('file.mime_type.guesser')
->guess($values['uri']);
}
}