Skip to content

Commit

Permalink
ENH ensure file title constructed from original filename
Browse files Browse the repository at this point in the history
  • Loading branch information
satrun77 committed Aug 21, 2024
1 parent e447930 commit f11e062
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/File.php
Original file line number Diff line number Diff line change
Expand Up @@ -728,10 +728,10 @@ protected function onBeforeWrite()
// Update title
if (!$title) {
// Generate a readable title, dashes and underscores replaced by whitespace,
// and any file extensions removed.
// and any file extensions removed, from the file original name
$this->setField(
'Title',
str_replace(['-','_'], ' ', preg_replace('/\.[^.]+$/', '', $name ?? '') ?? '')
str_replace(['-','_'], ' ', (string) preg_replace('/\.[^.]+$/', '', (string) $this->getField('OriginalName')))
);
}

Expand Down
3 changes: 3 additions & 0 deletions src/Upload.php
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,9 @@ public function loadIntoFile($tmpFile, $file = null, $folderPath = false)
}
$filename = $this->resolveExistingFile($filename);

// Store teh actual file name before any transformation from getValidFilename
$this->file->setField('OriginalName', $tmpFile['name']);

// Save changes to underlying record (if it's a DataObject)
$this->storeTempFile($tmpFile, $filename, $this->file);
if ($this->file instanceof DataObject) {
Expand Down

0 comments on commit f11e062

Please sign in to comment.