Skip to content

Commit 4225d0a

Browse files
author
Gabriel Galvao da Gama
committed
Added method to handle file extension for non existing files
1 parent 08ba639 commit 4225d0a

File tree

1 file changed

+15
-1
lines changed
  • app/code/Magento/Customer/Model/Metadata/Form

1 file changed

+15
-1
lines changed

app/code/Magento/Customer/Model/Metadata/Form/File.php

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ protected function _validateByRules($value)
182182
{
183183
$label = $value['name'];
184184
$rules = $this->getAttribute()->getValidationRules();
185-
$extension = $this->fileProcessor->getStat($value['name'])['extension'];
185+
$extension = $this->getFileExtension($value['name']);
186186
$fileExtensions = ArrayObjectSearch::getArrayElementByName(
187187
$rules,
188188
'file_extensions'
@@ -220,6 +220,20 @@ protected function _validateByRules($value)
220220
return [];
221221
}
222222

223+
/**
224+
* Get file extension from the file if it exists, otherwise, get from filename.
225+
*
226+
* @param string $fileName
227+
* @return string
228+
*/
229+
private function getFileExtension(string $fileName): string
230+
{
231+
if ($this->fileProcessor->isExist($fileName)) {
232+
return $this->fileProcessor->getStat($fileName)['extension'];
233+
}
234+
return pathinfo($fileName, PATHINFO_EXTENSION);
235+
}
236+
223237
/**
224238
* Helper function that checks if the file was uploaded.
225239
*

0 commit comments

Comments
 (0)