8
8
use Illuminate \Contracts \View \View ;
9
9
use Illuminate \View \ComponentAttributeBag ;
10
10
use MoonShine \Components \FieldsGroup ;
11
+ use MoonShine \Contracts \Fields \FieldsWrapper ;
11
12
use MoonShine \Decorations \LineBreak ;
12
13
use Throwable ;
13
14
14
15
/**
15
16
* @method static static make(Closure|string $label, ?Closure $fields = null)
16
17
*/
17
- class Td extends Template
18
+ class Td extends Template implements FieldsWrapper
18
19
{
19
20
private ?Closure $ conditionalFields = null ;
20
21
@@ -60,6 +61,10 @@ public function hasConditionalFields(): bool
60
61
61
62
public function getConditionalFields (): array
62
63
{
64
+ if (\is_null ($ this ->getData ())) {
65
+ return [];
66
+ }
67
+
63
68
return value ($ this ->conditionalFields , $ this ->getData (), $ this );
64
69
}
65
70
@@ -105,12 +110,10 @@ protected function resolvePreview(): string|View
105
110
return parent ::resolvePreview ();
106
111
}
107
112
108
- $ fields = $ this ->hasConditionalFields ()
109
- ? $ this ->getConditionalFields ()
110
- : $ this ->getFields ();
113
+ $ fields = $ this ->getFields ();
111
114
112
115
return FieldsGroup::make (
113
- Fields:: make ( $ fields)
116
+ $ fields
114
117
)
115
118
->mapFields (fn (Field $ field , int $ index ): Field => $ field
116
119
->resolveFill ($ this ->toRawValue (withoutModify: true ), $ this ->getData ())
@@ -119,4 +122,11 @@ protected function resolvePreview(): string|View
119
122
->forcePreview ())
120
123
->render ();
121
124
}
122
- }
125
+
126
+ public function getFields (): Fields
127
+ {
128
+ return $ this ->hasConditionalFields ()
129
+ ? Fields::make ($ this ->getConditionalFields ())
130
+ : Fields::make ($ this ->getRawFields ());
131
+ }
132
+ }
0 commit comments