9 use Magento\Customer\Model\FileProcessorFactory;
49 private $uploaderFactory;
95 $this->_fileValidator = $fileValidator;
96 $this->_fileSystem = $fileSystem;
97 $this->uploaderFactory = $uploaderFactory;
100 $this->fileProcessor = $this->fileProcessorFactory->create([
'entityTypeCode' => $this->_entityTypeCode]);
112 if ($this->_requestScope) {
114 if (strpos($this->_requestScope,
'/') !==
false) {
115 $scopes = explode(
'/', $this->_requestScope);
116 $mainScope = array_shift($scopes);
122 if (!empty($_FILES[$mainScope])) {
123 foreach ($_FILES[$mainScope] as $fileKey => $scopeData) {
124 foreach ($scopes as $scopeName) {
125 if (isset($scopeData[$scopeName])) {
126 $scopeData = $scopeData[$scopeName];
128 $scopeData[$scopeName] = [];
132 if (isset($scopeData[$attrCode])) {
133 $value[$fileKey] = $scopeData[$attrCode];
136 }
elseif (isset($extend[0][
'file']) && !empty($extend[0][
'file'])) {
148 if (isset($_FILES[$attrCode])) {
149 $value = $_FILES[$attrCode];
155 if (!empty($extend[
'delete'])) {
180 $extensions = array_map(
'trim', $extensions);
182 return [
__(
'"%1" is not a valid file extension.',
$extension)];
189 if (!$this->_fileValidator->isValid(
$extension)) {
190 return $this->_fileValidator->getMessages();
194 return [
__(
'"%1" is not a valid file.',
$label)];
197 $maxFileSize = ArrayObjectSearch::getArrayElementByName(
201 if ($maxFileSize !==
null) {
203 if ($maxFileSize < $size) {
204 return [
__(
'"%1" exceeds the allowed file size.',
$label)];
227 if ($this->fileProcessor->isExist($temporaryFile)) {
249 $toDelete = !empty(
$value[
'delete']) ? true :
false;
250 $toUpload = !empty(
$value[
'tmp_name']) ? true :
false;
252 if (!$toUpload && !$toDelete && $this->_value) {
256 if (!
$attribute->isRequired() && !$toUpload) {
287 if (empty(
$value) && !empty($this->_value)) {
288 $this->fileProcessor->removeUploadedFile($this->_value);
293 if (
$value[
'file'] == $this->_value) {
312 $result = $this->fileProcessor->moveTemporaryFile(
$value[
'file']);
327 && !empty(
$value[
'delete'])
331 if (!empty(
$value[
'tmp_name'])) {
336 $mediaDir = $this->_fileSystem->getDirectoryWrite(DirectoryList::MEDIA);
340 $mediaDir->delete($this->_entityTypeCode .
'/' . ltrim($this->_value,
'/'));
344 if (!empty(
$value[
'tmp_name'])) {
346 $uploader = $this->uploaderFactory->create([
'fileId' =>
$value]);
347 $uploader->setFilesDispersion(
true);
348 $uploader->setFilenamesCaseSensitivity(
false);
349 $uploader->setAllowRenameFiles(
true);
350 $uploader->save($mediaDir->getAbsolutePath($this->_entityTypeCode),
$value[
'name']);
351 $result = $uploader->getUploadedFileName();
353 $this->_logger->critical($e);
376 case \Magento\Customer\Model\Metadata\ElementFactory::OUTPUT_FORMAT_JSON:
elseif(isset( $params[ 'redirect_parent']))
if(!validateInput($options, $requiredOptions)) $fileExtensions