Example #1
0
 /**
  * Save uploaded file before saving config value
  *
  * @return $this
  * @throws \Magento\Framework\Exception\LocalizedException
  */
 public function beforeSave()
 {
     $value = $this->getValue();
     $tmpName = $this->_requestData->getTmpName($this->getPath());
     $file = [];
     if ($tmpName) {
         $file['tmp_name'] = $tmpName;
         $file['name'] = $this->_requestData->getName($this->getPath());
     } elseif (!empty($value['tmp_name'])) {
         $file['tmp_name'] = $value['tmp_name'];
         $file['name'] = $value['value'];
     }
     if (!empty($file)) {
         return parent::beforeSave();
     }
     if (is_array($value) && !empty($value['delete'])) {
         $this->setValue('');
     } else {
         if (!empty($value['value'])) {
             $this->setValue($value['value']);
         } else {
             $this->unsValue();
         }
     }
     return $this;
 }
 /**
  * Save uploaded file before saving config value
  *
  * Save changes and delete file if "delete" option passed
  *
  * @return $this
  */
 public function beforeSave()
 {
     $value = $this->getValue();
     $deleteFlag = is_array($value) && !empty($value['delete']);
     $fileTmpName = $this->getTmpFileName();
     if ($this->getOldValue() && ($fileTmpName || $deleteFlag)) {
         $this->_mediaDirectory->delete(self::UPLOAD_DIR . '/' . $this->getOldValue());
     }
     return parent::beforeSave();
 }
Example #3
0
 /**
  * Save uploaded file before saving config value
  *
  * Save changes and delete file if "delete" option passed
  *
  * @return $this
  */
 public function beforeSave()
 {
     $value = $this->getValue();
     $deleteFlag = is_array($value) && !empty($value['delete']);
     $fileTmpName = $_FILES['groups']['tmp_name'][$this->getGroupId()]['fields'][$this->getField()]['value'];
     if ($this->getOldValue() && ($fileTmpName || $deleteFlag)) {
         $this->_mediaDirectory->delete(self::UPLOAD_DIR . '/' . $this->getOldValue());
     }
     return parent::beforeSave();
 }