Skip to content

Commit 50b33f5

Browse files
authored
Merge pull request #708 from code16/fix-upload-embed-dimensions
Fix embed dimensions not preserved
2 parents 9658e6c + 9861388 commit 50b33f5

6 files changed

Lines changed: 30 additions & 2 deletions

File tree

src/Form/Eloquent/Uploads/Transformers/SharpUploadModelFormAttributeTransformer.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,12 @@ public function apply($value, $instance = null, $attribute = null)
4747
$instance = (object) [
4848
$attribute => static::getUploadModelClass()::make([
4949
'file_name' => $value['file_name'] ?? $value['path'],
50-
'filters' => $value['filters'] ?? null,
5150
'mime_type' => $value['mime_type'] ?? null,
5251
'disk' => $value['disk'],
5352
'size' => $value['size'] ?? null,
53+
'filters' => $value['filters'] ?? null,
54+
'width' => $value['width'] ?? null,
55+
'height' => $value['height'] ?? null,
5456
]),
5557
];
5658

@@ -78,8 +80,10 @@ public function apply($value, $instance = null, $attribute = null)
7880
'thumbnail',
7981
'playable_preview_url',
8082
'size',
81-
'filters',
8283
'mime_type',
84+
'filters',
85+
'width',
86+
'height',
8387
];
8488

8589
return array_merge(

src/Form/Fields/Formatters/UploadFormatter.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,8 @@ protected function normalizeFromFront(?array $value, ?array $formatted = null):
112112
'mime_type' => $formatted['mime_type'] ?? $value['mime_type'] ?? null,
113113
'disk' => $formatted['disk'] ?? $value['disk'] ?? null,
114114
'filters' => $formatted['filters'] ?? $value['filters'] ?? null,
115+
'width' => $value['width'] ?? null,
116+
'height' => $value['height'] ?? null,
115117
])->whereNotNull()->toArray();
116118
}
117119

src/View/Components/Image.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ public function __construct(
3131
'file_name' => $this->file['file_name'],
3232
'disk' => $this->file['disk'] ?? null,
3333
'filters' => $this->file['filters'] ?? null,
34+
'width' => $this->file['width'] ?? null,
35+
'height' => $this->file['height'] ?? null,
3436
]);
3537
$this->disk = Storage::disk($this->fileModel->disk);
3638
$this->exists = $this->disk->exists($this->fileModel->file_name);

tests/Unit/Form/Eloquent/Uploads/Transformers/SharpUploadModelFormAttributeTransformerTest.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,8 @@
268268
'disk' => 'local',
269269
'filters' => [],
270270
'mime_type' => 'image/png',
271+
'width' => 100,
272+
'height' => 100,
271273
];
272274

273275
$transformer = (new SharpUploadModelFormAttributeTransformer())->dynamicInstance();
@@ -283,6 +285,8 @@
283285
'playable_preview_url' => null,
284286
'filters' => [],
285287
'mime_type' => 'image/png',
288+
'width' => 100,
289+
'height' => 100,
286290
],
287291
$transformer->apply($uploadData, null, 'picture'),
288292
);

tests/Unit/Form/Fields/Formatters/EditorFormatterTest.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,8 @@
134134
'size' => 120,
135135
'mime_type' => 'image/jpeg',
136136
'disk' => 'local',
137+
'width' => 600,
138+
'height' => 600,
137139
])),
138140
e(json_encode([
139141
'file_name' => 'data/Posts/1/doc.pdf',
@@ -160,6 +162,8 @@
160162
'mime_type' => 'image/jpeg',
161163
'filters' => null,
162164
'id' => null,
165+
'width' => 600,
166+
'height' => 600,
163167
],
164168
'legend' => 'Legendary',
165169
'_locale' => null,
@@ -175,6 +179,8 @@
175179
'mime_type' => 'application/pdf',
176180
'filters' => null,
177181
'id' => null,
182+
'width' => null,
183+
'height' => null,
178184
],
179185
'legend' => null,
180186
'_locale' => null,
@@ -271,6 +277,8 @@
271277
'size' => 120,
272278
'mime_type' => 'image/jpeg',
273279
'disk' => 'local',
280+
'width' => 600,
281+
'height' => 600,
274282
]))
275283
);
276284

@@ -298,6 +306,8 @@
298306
'mime_type' => 'image/jpeg',
299307
'filters' => null,
300308
'id' => null,
309+
'width' => 600,
310+
'height' => 600,
301311
],
302312
'_html' => sprintf('<img src="%s"> My <em>contentful</em> content',
303313
$thumbnail,

tests/Unit/Show/Fields/Formatters/TextFormatterTest.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@
4040
'size' => 120,
4141
'mime_type' => 'image/jpeg',
4242
'disk' => 'local',
43+
'width' => 600,
44+
'height' => 600,
4345
])),
4446
e(json_encode([
4547
'file_name' => 'data/Posts/1/doc.pdf',
@@ -66,6 +68,8 @@
6668
'mime_type' => 'image/jpeg',
6769
'filters' => null,
6870
'id' => null,
71+
'width' => 600,
72+
'height' => 600,
6973
],
7074
'legend' => 'Legendary',
7175
'_locale' => null,
@@ -81,6 +85,8 @@
8185
'mime_type' => 'application/pdf',
8286
'filters' => null,
8387
'id' => null,
88+
'width' => null,
89+
'height' => null,
8490
],
8591
'legend' => null,
8692
'_locale' => null,

0 commit comments

Comments
 (0)