2
2
3
3
namespace Code16 \OzuClient \OzuCms ;
4
4
5
+ use Closure ;
5
6
use Code16 \OzuClient \OzuCms \Form \OzuBelongsToField ;
7
+ use Code16 \OzuClient \OzuCms \Form \OzuEditorField ;
8
+ use Code16 \OzuClient \OzuCms \Form \OzuEditorToolbarEnum ;
6
9
use Code16 \OzuClient \OzuCms \Form \OzuField ;
10
+ use Code16 \OzuClient \OzuCms \Form \OzuImageField ;
11
+ use Code16 \OzuClient \OzuCms \Form \OzuTextField ;
7
12
use Illuminate \Support \Collection ;
8
13
9
14
class OzuCollectionFormConfig
10
15
{
16
+ protected ?OzuTextField $ titleField ;
17
+ protected bool $ hideTitleField = false ;
18
+
19
+ protected ?OzuImageField $ coverField ;
20
+ protected bool $ hideCoverField = false ;
21
+
22
+ protected ?OzuEditorField $ contentField ;
23
+ protected bool $ hideContentField = false ;
24
+
11
25
protected array $ fields = [];
12
26
protected ?OzuBelongsToField $ belongsToField = null ;
13
27
@@ -18,6 +32,57 @@ public function addCustomField(OzuField $field): self
18
32
return $ this ;
19
33
}
20
34
35
+ public function configureTitleField (Closure $ callback ): self
36
+ {
37
+ unset($ this ->titleField );
38
+
39
+ $ titleField = $ this ->titleField ();
40
+ $ this ->titleField = tap ($ titleField , fn (&$ titleField ) => $ callback ($ titleField ));
41
+
42
+ return $ this ;
43
+ }
44
+
45
+ public function hideTitleField (bool $ hideTitleField = true ): self
46
+ {
47
+ $ this ->hideTitleField = $ hideTitleField ;
48
+
49
+ return $ this ;
50
+ }
51
+
52
+ public function configureCoverField (Closure $ callback ): self
53
+ {
54
+ unset($ this ->coverField );
55
+
56
+ $ coverField = $ this ->coverField ();
57
+ $ this ->coverField = tap ($ coverField , fn (&$ coverField ) => $ callback ($ coverField ));
58
+
59
+ return $ this ;
60
+ }
61
+
62
+ public function hideCoverField (bool $ hideCoverField = true ): self
63
+ {
64
+ $ this ->hideCoverField = $ hideCoverField ;
65
+
66
+ return $ this ;
67
+ }
68
+
69
+ public function configureContentField (Closure $ callback ): self
70
+ {
71
+ unset($ this ->contentField );
72
+
73
+ $ contentField = $ this ->contentField ();
74
+ $ this ->contentField = tap ($ contentField , fn (&$ contentField ) => $ callback ($ contentField ));
75
+
76
+ return $ this ;
77
+ }
78
+
79
+ public function hideContentField (bool $ hideContentField = true ): self
80
+ {
81
+ $ this ->hideContentField = $ hideContentField ;
82
+
83
+ return $ this ;
84
+ }
85
+
21
86
public function declareBelongsToField (string $ ozuModelClass , string $ label , bool $ required = true ): self
22
87
{
23
88
$ ozuCollectionKey = app ($ ozuModelClass )->ozuCollectionKey ();
@@ -32,9 +97,59 @@ public function declareBelongsToField(string $ozuModelClass, string $label, bool
32
97
33
98
public function customFields (): Collection
34
99
{
35
- return collect ([
36
- $ this ->belongsToField ,
37
- ...$ this ->fields
38
- ])->whereNotNull ();
100
+ return collect (
101
+ [
102
+ $ this ->belongsToField ,
103
+ ...$ this ->fields
104
+ ])
105
+ ->whereNotNull ()
106
+ ->values ();
107
+ }
108
+
109
+ public function titleField (): ?OzuTextField
110
+ {
111
+ if ($ this ->hideTitleField ) {
112
+ return null ;
113
+ }
114
+
115
+ if (!isset ($ this ->titleField )) {
116
+ $ this ->titleField = OzuField::makeText ('title ' );
117
+ }
118
+
119
+ return $ this ->titleField ;
120
+ }
121
+
122
+ public function coverField (): ?OzuImageField
123
+ {
124
+ if ($ this ->hideCoverField ) {
125
+ return null ;
126
+ }
127
+
128
+ if (!isset ($ this ->coverField )) {
129
+ $ this ->coverField = OzuField::makeImage ('cover ' )
130
+ ->setMaxFileSizeInMB (3 );
131
+ }
132
+
133
+ return $ this ->coverField ;
134
+ }
135
+
136
+ public function contentField (): ?OzuEditorField
137
+ {
138
+ if ($ this ->hideContentField ) {
139
+ return null ;
140
+ }
141
+
142
+ if (!isset ($ this ->contentField )) {
143
+ $ this ->contentField = OzuField::makeEditor ('content ' )
144
+ ->setToolbar ([
145
+ OzuEditorToolbarEnum::Bold,
146
+ OzuEditorToolbarEnum::Italic,
147
+ OzuEditorToolbarEnum::Separator,
148
+ OzuEditorToolbarEnum::BulletList,
149
+ OzuEditorToolbarEnum::Link,
150
+ ]);
151
+ }
152
+
153
+ return $ this ->contentField ;
39
154
}
40
155
}
0 commit comments