diff --git a/classes/UploadStorage.php b/classes/UploadStorage.php index 8a21417..13be1a5 100644 --- a/classes/UploadStorage.php +++ b/classes/UploadStorage.php @@ -30,12 +30,14 @@ class UploadStorage { 'crop' => $this->data['crop'] ]); - return $sourcePath.'/'.$fileName; + return $this->getFileData($sourcePath.'/'.$fileName); } public function getFileData($filename) { $realname = preg_replace('/^source/', 'cropped', $filename); + $realname = $this->storage()->exists($realname) ? $realname : $filename; + return [ 'url' => $this->storage()->url($realname), 'type' => $this->storage()->mimeType($filename), diff --git a/formwidgets/Responsiveimage.php b/formwidgets/Responsiveimage.php index 4c612e4..8e1bc39 100644 --- a/formwidgets/Responsiveimage.php +++ b/formwidgets/Responsiveimage.php @@ -137,15 +137,6 @@ class Responsiveimage extends FormWidgetBase return $record; } - public function getLoadValue() { - $value = parent::getLoadValue(); - if (!$value) { - return null; - } - - return app(UploadStorage::class)->getFileData($value['file']); - } - /** * Returns the escaped and translated prompt text to display according to the type. * @return string diff --git a/formwidgets/responsiveimage/assets/src/App.vue b/formwidgets/responsiveimage/assets/src/App.vue index d667140..588fadb 100644 --- a/formwidgets/responsiveimage/assets/src/App.vue +++ b/formwidgets/responsiveimage/assets/src/App.vue @@ -111,6 +111,9 @@ export default { asString() { return JSON.stringify(this.content); }, + formData() { + return $(this.$el).closest('form').serializeArray(); + }, dropzoneOptions() { return { paramName: 'file_data', @@ -170,12 +173,15 @@ export default { }, onSend(file, xhr, formData) { formData.append('extraData', JSON.stringify(this.extraData[file.name])); + this.formData.forEach((v) => { + formData.append(v.name, v.value); + }); }, onMount() { - if (this.value === null) { return; } + if (!this.value) { return; } this.addVisible = false; - var file = { size: this.value.size, name: this.value.name, type: this.value.type }; - this.$refs.dropzone.manuallyAddFile(file, this.value.url); + var file = { size: this.value.file.size, name: this.value.file.name, type: this.value.file.type }; + this.$refs.dropzone.manuallyAddFile(file, this.value.file.url); }, onRemove(file, error, xhr) { var _cls = this;