Skip to content

Commit f429ac8

Browse files
Baspagithub-actions[bot]
authored andcommitted
fix: styling
1 parent 68cb7c6 commit f429ac8

File tree

4 files changed

+57
-69
lines changed

4 files changed

+57
-69
lines changed

packages/core/src/Models/Media.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ public function getEditAttribute(): ?array
4747
}
4848

4949
$result = is_string($edit->pivot->meta) ? json_decode($edit->pivot->meta, true) : $edit->pivot->meta;
50+
5051
return $result;
5152
}
5253

@@ -56,6 +57,7 @@ public function getEditAttribute(): ?array
5657
}
5758

5859
$result = is_string($edit->pivot->meta) ? json_decode($edit->pivot->meta, true) : $edit->pivot->meta;
60+
5961
return $result;
6062
}
6163
}

packages/filament-uploadcare-field/src/Forms/Components/Uploadcare.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,7 @@ public function maxLocalFileSize(string $size): static
313313
public function getState(): mixed
314314
{
315315
$state = parent::getState();
316-
316+
317317
// Handle double-encoded JSON or JSON strings
318318
if (is_string($state) && json_validate($state)) {
319319
$decoded = json_decode($state, true);
@@ -444,7 +444,7 @@ private static function resolveUlidsToUploadcareState(array $items, ?Model $reco
444444
->whereIn('media_ulid', array_values($ulidsToResolve))
445445
->get()
446446
->keyBy('ulid');
447-
447+
448448
}
449449
} catch (\Exception $e) {
450450
}
@@ -458,7 +458,8 @@ private static function resolveUlidsToUploadcareState(array $items, ?Model $reco
458458
->whereIn('media_ulid', array_values($ulidsToResolve))
459459
->get()
460460
->keyBy('ulid');
461-
} catch (\Exception $e) {}
461+
} catch (\Exception $e) {
462+
}
462463
}
463464

464465
if (! $mediaItems || $mediaItems->isEmpty()) {

packages/uploadcare-field/src/Observers/ContentFieldValueObserver.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ private function parseItem(mixed $item): array
160160
} elseif (is_array($item)) {
161161
$uuid = $item['uuid'] ?? ($item['fileInfo']['uuid'] ?? null);
162162
$meta = $item;
163-
163+
164164
// Try to extract modifiers from cdnUrl if not explicitly present or if we want to be sure
165165
if (isset($item['cdnUrl']) && is_string($item['cdnUrl']) && filter_var($item['cdnUrl'], FILTER_VALIDATE_URL)) {
166166
preg_match('/([a-f0-9-]{36})/i', $item['cdnUrl'], $matches, PREG_OFFSET_CAPTURE);

packages/uploadcare-field/src/Uploadcare.php

Lines changed: 50 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ public static function make(string $name, Field $field): Input
4949
->withMetadata()
5050
->removeCopyright()
5151
->dehydrateStateUsing(function ($state, $component, $record) {
52-
52+
5353
if (is_string($state) && json_validate($state)) {
5454
$state = json_decode($state, true);
5555
}
@@ -67,8 +67,7 @@ public static function make(string $name, Field $field): Input
6767

6868
return $item;
6969
}, $state);
70-
71-
70+
7271
/*
7372
// Ensure we return a single object (or string) for non-multiple fields during dehydration
7473
// to prevent Filament from clearing the state.
@@ -157,46 +156,45 @@ public static function make(string $name, Field $field): Input
157156
$foundModels = $mediaModel::whereIn('ulid', $potentialUlids->toArray())->get();
158157
}
159158

160-
if ($foundModels->isNotEmpty()) {
161-
if ($record) {
162-
$foundModels->each(function($m) use ($record, $fieldName) {
163-
$mediaUlid = $m->ulid ?? 'UNKNOWN';
164-
165-
166-
if ($m->relationLoaded('pivot') && $m->pivot && $m->pivot->meta) {
167-
$meta = is_string($m->pivot->meta) ? json_decode($m->pivot->meta, true) : $m->pivot->meta;
168-
if (is_array($meta)) {
169-
$m->setAttribute('hydrated_edit', $meta);
170-
}
171-
}
172-
$contextModel = clone $record;
173-
if ($m->relationLoaded('pivot') && $m->pivot) {
174-
$contextModel->setRelation('pivot', $m->pivot);
175-
} else {
176-
$dummyPivot = new \Backstage\Models\ContentFieldValue();
177-
$dummyPivot->setAttribute('meta', null);
178-
$contextModel->setRelation('pivot', $dummyPivot);
179-
}
180-
$m->setRelation('edits', new \Illuminate\Database\Eloquent\Collection([$contextModel]));
181-
});
182-
}
183-
184-
if ($foundModels->count() === 1 && count($state) > 1) {
185-
$newState = [self::mapMediaToValue($foundModels->first())];
186-
} else {
187-
$newState = $foundModels->map(fn($m) => self::mapMediaToValue($m))->all();
188-
}
189-
190-
} else {
191-
// Process each item in the state array
192-
$extractedFiles = [];
193-
194-
foreach ($state as $item) {
195-
if (is_array($item)) {
196-
$extractedFiles[] = self::mapMediaToValue($item);
197-
198-
continue;
199-
}
159+
if ($foundModels->isNotEmpty()) {
160+
if ($record) {
161+
$foundModels->each(function ($m) use ($record) {
162+
$mediaUlid = $m->ulid ?? 'UNKNOWN';
163+
164+
if ($m->relationLoaded('pivot') && $m->pivot && $m->pivot->meta) {
165+
$meta = is_string($m->pivot->meta) ? json_decode($m->pivot->meta, true) : $m->pivot->meta;
166+
if (is_array($meta)) {
167+
$m->setAttribute('hydrated_edit', $meta);
168+
}
169+
}
170+
$contextModel = clone $record;
171+
if ($m->relationLoaded('pivot') && $m->pivot) {
172+
$contextModel->setRelation('pivot', $m->pivot);
173+
} else {
174+
$dummyPivot = new \Backstage\Models\ContentFieldValue;
175+
$dummyPivot->setAttribute('meta', null);
176+
$contextModel->setRelation('pivot', $dummyPivot);
177+
}
178+
$m->setRelation('edits', new \Illuminate\Database\Eloquent\Collection([$contextModel]));
179+
});
180+
}
181+
182+
if ($foundModels->count() === 1 && count($state) > 1) {
183+
$newState = [self::mapMediaToValue($foundModels->first())];
184+
} else {
185+
$newState = $foundModels->map(fn ($m) => self::mapMediaToValue($m))->all();
186+
}
187+
188+
} else {
189+
// Process each item in the state array
190+
$extractedFiles = [];
191+
192+
foreach ($state as $item) {
193+
if (is_array($item)) {
194+
$extractedFiles[] = self::mapMediaToValue($item);
195+
196+
continue;
197+
}
200198

201199
if (! is_string($item)) {
202200
continue;
@@ -257,7 +255,6 @@ public static function make(string $name, Field $field): Input
257255

258256
}
259257

260-
261258
if ($newState !== $state) {
262259
$component->state($newState);
263260
}
@@ -437,18 +434,18 @@ public static function mutateFormDataCallback(Model $record, Field $field, array
437434
// 1. Try to get from property first (set by EditContent)
438435
if (isset($record->values) && is_array($record->values)) {
439436
$values = $record->values[$field->ulid] ?? null;
440-
437+
441438
}
442439

443440
// 2. Fallback to getFieldValueFromRecord which checks relationships
444441
if ($values === null) {
445442
$values = self::getFieldValueFromRecord($record, $field);
446-
443+
447444
}
448445

449446
if ($values === '' || $values === [] || $values === null || empty($values)) {
450447
$data[$record->valueColumn ?? 'values'][$field->ulid] = [];
451-
448+
452449
return $data;
453450
}
454451

@@ -630,8 +627,6 @@ private static function findFieldValues(array $data, Field $field): mixed
630627
$fieldUlid = (string) $field->ulid;
631628
$fieldSlug = (string) $field->slug;
632629

633-
634-
635630
// Try direct key first (most common)
636631
if (array_key_exists($fieldUlid, $data)) {
637632
return $data[$fieldUlid];
@@ -643,10 +638,10 @@ private static function findFieldValues(array $data, Field $field): mixed
643638
// Recursive search that correctly traverses lists (repeaters/builders)
644639
$notFound = new \stdClass;
645640
$findInNested = function ($array, $ulid, $slug, $depth = 0) use (&$findInNested, $notFound) {
646-
641+
647642
// First pass: look for direct keys at this level
648643
if (array_key_exists($ulid, $array)) {
649-
644+
650645
return $array[$ulid];
651646
}
652647
if (array_key_exists($slug, $array)) {
@@ -674,8 +669,6 @@ private static function findFieldValues(array $data, Field $field): mixed
674669
} else {
675670
$found = true;
676671
}
677-
678-
679672

680673
return $result;
681674
}
@@ -980,7 +973,6 @@ private static function normalizeCurrentState(mixed $state): array
980973

981974
public function hydrate(mixed $value, ?Model $model = null): mixed
982975
{
983-
984976

985977
if (empty($value)) {
986978
return null;
@@ -997,8 +989,6 @@ public function hydrate(mixed $value, ?Model $model = null): mixed
997989
// Try to hydrate from relation
998990
$hydratedFromModel = self::hydrateFromModel($model, $value, true);
999991

1000-
1001-
1002992
if ($hydratedFromModel !== null && ! empty($hydratedFromModel)) {
1003993
// Check config to decide if we should return single or multiple
1004994
$config = $this->field_model->config ?? $model->field->config ?? [];
@@ -1147,8 +1137,6 @@ public static function mapMediaToValue(mixed $media): array | string
11471137
}
11481138
}
11491139

1150-
1151-
11521140
if (is_array($data)) {
11531141
// Extract modifiers from cdnUrl if missing
11541142
if (isset($data['cdnUrl']) && ! isset($data['cdnUrlModifiers'])) {
@@ -1204,24 +1192,21 @@ private static function hydrateFromModel(?Model $model, mixed $value = null, boo
12041192

12051193
$media->each(function ($m) use ($model) {
12061194
$mediaUlid = $m->ulid ?? 'UNKNOWN';
1207-
1208-
1195+
12091196
if ($m->pivot && $m->pivot->meta) {
12101197
$pivotMeta = is_string($m->pivot->meta) ? json_decode($m->pivot->meta, true) : $m->pivot->meta;
1211-
1212-
1198+
12131199
if (is_array($pivotMeta)) {
12141200
$m->setAttribute('hydrated_edit', $pivotMeta);
12151201
if ($model) {
12161202
$contextModel = clone $model;
12171203
$contextModel->setRelation('pivot', $m->pivot);
12181204
$m->setRelation('edits', new \Illuminate\Database\Eloquent\Collection([$contextModel]));
12191205
}
1220-
1221-
1206+
12221207
}
12231208
} else {
1224-
1209+
12251210
}
12261211
});
12271212

0 commit comments

Comments
 (0)