File tree Expand file tree Collapse file tree 2 files changed +37
-1
lines changed
Expand file tree Collapse file tree 2 files changed +37
-1
lines changed Original file line number Diff line number Diff line change @@ -32,7 +32,7 @@ public function size(int $value): static
3232 */
3333 public function newOption (mixed $ value , string $ label ): Option
3434 {
35- return parent :: newOption ( $ value , $ label )
35+ return ( new CheckboxOption ( $ value , $ label) )
3636 ->class ('form-check__control ' )
3737 ->setAttributes ([
3838 'type ' => 'checkbox ' ,
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ declare (strict_types=1 );
4+
5+ namespace Cone \Root \Fields ;
6+
7+ class CheckboxOption extends Option
8+ {
9+ /**
10+ * Set the "selected" HTML attribute.
11+ */
12+ public function selected (bool $ value = true ): static
13+ {
14+ return $ this ->checked ($ value );
15+ }
16+
17+ /**
18+ * Set the "selected" HTML attribute.
19+ */
20+ public function checked (bool $ value = true ): static
21+ {
22+ return $ this ->setAttribute ('checked ' , $ value );
23+ }
24+
25+ /**
26+ * Get the array representation of the object.
27+ */
28+ public function toArray (): array
29+ {
30+ $ value = parent ::toArray ();
31+
32+ unset($ value ['selected ' ]);
33+
34+ return array_merge ($ value , ['checked ' => $ this ->getAttribute ('checked ' )]);
35+ }
36+ }
You can’t perform that action at this time.
0 commit comments