Skip to content

Commit 381bf4e

Browse files
committed
allow the configuration of valueWithoutPath call.
1 parent bf48007 commit 381bf4e

File tree

3 files changed

+15
-8
lines changed

3 files changed

+15
-8
lines changed

src/app/Library/Uploaders/Support/Interfaces/UploaderInterface.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,4 +60,6 @@ public function canHandleMultipleFiles(): bool;
6060
public function isRelationship(): bool;
6161

6262
public function getPreviousFiles(Model $entry): mixed;
63+
64+
public function getValueWithoutPath(?string $value = null): ?string;
6365
}

src/app/Library/Uploaders/Support/Traits/HandleRepeatableUploads.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -282,16 +282,16 @@ private function getPreviousRepeatableValues(Model $entry, UploaderInterface $up
282282
return $previousValues ?? [];
283283
}
284284

285-
private function getValuesWithPathStripped(array|string|null $item, UploaderInterface $upload)
285+
private function getValuesWithPathStripped(array|string|null $item, UploaderInterface $uploader)
286286
{
287-
$uploadedValues = $item[$upload->getName()] ?? null;
287+
$uploadedValues = $item[$uploader->getName()] ?? null;
288288
if (is_array($uploadedValues)) {
289-
return array_map(function ($value) use ($upload) {
290-
return Str::after($value, $upload->getPath());
289+
return array_map(function ($value) use ($uploader) {
290+
return $uploader->getValueWithoutPath($value);
291291
}, $uploadedValues);
292292
}
293293

294-
return isset($uploadedValues) ? Str::after($uploadedValues, $upload->getPath()) : null;
294+
return isset($uploadedValues) ? $uploader->getValueWithoutPath($uploadedValues) : null;
295295
}
296296

297297
private function deleteRelationshipFiles(Model $entry): void

src/app/Library/Uploaders/Uploader.php

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,11 @@ public function getPreviousFiles(Model $entry): mixed
189189
return $value[$this->getAttributeName()] ?? null;
190190
}
191191

192+
public function getValueWithoutPath(?string $value = null): ?string
193+
{
194+
return $value ? Str::after($value, $this->path) : null;
195+
}
196+
192197
/*******************************
193198
* Setters - fluently configure the uploader
194199
*******************************/
@@ -229,13 +234,13 @@ private function retrieveFiles(Model $entry): Model
229234
$values = $entry->{$this->attachedToFakeField};
230235
$values = is_string($values) ? json_decode($values, true) : (array) $values;
231236

232-
$values[$this->getAttributeName()] = isset($values[$this->getAttributeName()]) ? Str::after($values[$this->getAttributeName()], $this->path) : null;
237+
$values[$this->getAttributeName()] = isset($values[$this->getAttributeName()]) ? $this->getValueWithoutPath($values[$this->getAttributeName()]) : null;
233238
$entry->{$this->attachedToFakeField} = json_encode($values);
234239

235240
return $entry;
236241
}
237242

238-
$entry->{$this->getAttributeName()} = Str::after($value, $this->path);
243+
$entry->{$this->getAttributeName()} = $this->getValueWithoutPath($value);
239244

240245
return $entry;
241246
}
@@ -277,7 +282,7 @@ private function performFileDeletion(Model $entry)
277282
}
278283

279284
/*******************************
280-
* Private helper methods
285+
* helper methods
281286
*******************************/
282287
private function getPathFromConfiguration(array $crudObject, array $configuration): string
283288
{

0 commit comments

Comments
 (0)