diff --git a/src/FileTrait.php b/src/FileTrait.php index 67589bd7..47d5334f 100644 --- a/src/FileTrait.php +++ b/src/FileTrait.php @@ -110,7 +110,18 @@ protected function fileCreateEntity(\StdClass $stub): FileInterface { } } - return \Drupal::service('file.repository')->writeData(file_get_contents($path), $destination, FileSystemInterface::EXISTS_REPLACE); + $entity = \Drupal::service('file.repository')->writeData(file_get_contents($path), $destination, FileSystemInterface::EXISTS_REPLACE); + + foreach ($stub as $property => $value) { + // If path or URI has been specified then the value has already been handled. + if (in_array($property, ['path', 'uri'])) { + continue; + } + $entity->set($property, $value); + } + + $entity->save(); + return $entity; } /**