17 class File extends \Magento\Eav\Model\Attribute\Data\AbstractData
51 \
Magento\Framework\Stdlib\DateTime\TimezoneInterface $localeDate,
53 \
Magento\Framework\Locale\ResolverInterface $localeResolver,
58 parent::__construct($localeDate,
$logger, $localeResolver);
60 $this->_fileValidator = $fileValidator;
61 $this->_directory =
$filesystem->getDirectoryWrite(DirectoryList::MEDIA);
80 if ($this->_requestScope) {
82 if (strpos($this->_requestScope,
'/') !==
false) {
83 $scopes = explode(
'/', $this->_requestScope);
84 $mainScope = array_shift($scopes);
90 if (!empty($_FILES[$mainScope])) {
91 foreach ($_FILES[$mainScope] as $fileKey => $scopeData) {
92 foreach ($scopes as $scopeName) {
93 if (isset($scopeData[$scopeName])) {
94 $scopeData = $scopeData[$scopeName];
96 $scopeData[$scopeName] = [];
100 if (isset($scopeData[$attrCode])) {
101 $value[$fileKey] = $scopeData[$attrCode];
108 if (isset($_FILES[$attrCode])) {
109 $value = $_FILES[$attrCode];
115 if (!empty($extend[
'delete'])) {
134 if (!empty(
$rules[
'file_extensions'])) {
135 $extensions = explode(
',',
$rules[
'file_extensions']);
136 $extensions = array_map(
'trim', $extensions);
138 return [
__(
'"%1" is not a valid file extension.',
$label)];
145 if (!$this->_fileValidator->isValid(
$extension)) {
146 return $this->_fileValidator->getMessages();
150 return [
__(
'"%1" is not a valid file.',
$label)];
153 if (!empty(
$rules[
'max_file_size'])) {
155 if (
$rules[
'max_file_size'] < $size) {
156 return [
__(
'"%1" exceeds the allowed file size.',
$label)];
183 'tmp_name' => $dir .
$value 190 $toDelete = !empty(
$value[
'delete']) ? true :
false;
191 $toUpload = !empty(
$value[
'tmp_name']) || is_string(
$value) && !empty(
$value) ? true :
false;
197 if (!
$attribute->getIsRequired() && !$toUpload) {
201 if (
$attribute->getIsRequired() && !$toUpload) {
213 $this->_directory->delete($dir .
$value);
239 if (!empty(
$value[
'tmp_name'])) {
244 $destinationFolder =
$attribute->getEntityType()->getEntityTypeCode();
249 $file = $destinationFolder . $original;
250 if ($this->_directory->isExist($file)) {
251 $this->_directory->delete($file);
255 if (!empty(
$value[
'tmp_name'])) {
257 $uploader = new \Magento\Framework\File\Uploader(
$value);
258 $uploader->setFilesDispersion(
true);
259 $uploader->setFilenamesCaseSensitivity(
false);
260 $uploader->setAllowRenameFiles(
true);
261 $uploader->save($this->_directory->getAbsolutePath($destinationFolder),
$value[
'name']);
262 $fileName = $uploader->getUploadedFileName();
264 }
catch (\Exception $e) {
265 $this->_logger->critical($e);
298 case \Magento\Eav\Model\AttributeDataFactory::OUTPUT_FORMAT_JSON:
elseif(isset( $params[ 'redirect_parent']))
_getRequestValue(RequestInterface $request)
outputValue($format=\Magento\Eav\Model\AttributeDataFactory::OUTPUT_FORMAT_TEXT)
extractValue(RequestInterface $request)
$_validatorNotProtectedExtensions
__construct(\Magento\Framework\Stdlib\DateTime\TimezoneInterface $localeDate, \Psr\Log\LoggerInterface $logger, \Magento\Framework\Locale\ResolverInterface $localeResolver, \Magento\Framework\Url\EncoderInterface $urlEncoder, \Magento\MediaStorage\Model\File\Validator\NotProtectedExtension $fileValidator, \Magento\Framework\Filesystem $filesystem)
getData($key='', $index=null)