@@ -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