1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace WebTheory\Saveyour\Fields; |
4
|
|
|
|
5
|
|
|
use WebTheory\Saveyour\Concerns\SingleValueSelectionTrait; |
6
|
|
|
use WebTheory\Saveyour\Contracts\FormFieldInterface; |
7
|
|
|
use WebTheory\Saveyour\Contracts\RadioGroupSelectionInterface; |
8
|
|
|
|
9
|
|
|
class RadioGroup extends AbstractCompositeSelectionField implements FormFieldInterface |
10
|
|
|
{ |
11
|
|
|
use SingleValueSelectionTrait; |
12
|
|
|
|
13
|
|
|
/** |
14
|
|
|
* @var bool |
15
|
|
|
*/ |
16
|
|
|
protected $isInline = true; |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* @var RadioGroupSelectionInterface |
20
|
|
|
*/ |
21
|
|
|
protected $selectionProvider; |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* Get the value of isInline |
25
|
|
|
* |
26
|
|
|
* @return bool |
27
|
|
|
*/ |
28
|
|
|
public function isInline(): bool |
29
|
|
|
{ |
30
|
|
|
return $this->isInline; |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* Set the value of isInline |
35
|
|
|
* |
36
|
|
|
* @param bool $isInline |
37
|
|
|
* |
38
|
|
|
* @return self |
39
|
|
|
*/ |
40
|
|
|
public function setIsInline(bool $isInline) |
41
|
|
|
{ |
42
|
|
|
$this->isInline = $isInline; |
43
|
|
|
|
44
|
|
|
return $this; |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* Get the value of selectionProvider |
49
|
|
|
* |
50
|
|
|
* @return RadioGroupSelectionInterface |
51
|
|
|
*/ |
52
|
|
|
public function getSelectionProvider(): RadioGroupSelectionInterface |
53
|
|
|
{ |
54
|
|
|
return $this->selectionProvider; |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* Set the value of selectionProvider |
59
|
|
|
* |
60
|
|
|
* @param RadioGroupSelectionInterface $selectionProvider |
61
|
|
|
* |
62
|
|
|
* @return self |
63
|
|
|
*/ |
64
|
|
|
public function setSelectionProvider(RadioGroupSelectionInterface $selectionProvider) |
65
|
|
|
{ |
66
|
|
|
$this->selectionProvider = $selectionProvider; |
67
|
|
|
|
68
|
|
|
return $this; |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
/** |
72
|
|
|
* |
73
|
|
|
*/ |
74
|
|
|
protected function renderHtmlMarkup(): string |
75
|
|
|
{ |
76
|
|
|
$html = ''; |
77
|
|
|
|
78
|
|
|
foreach ($this->getSelectionData() as $selection) { |
79
|
|
|
$id = $this->defineSelectionId($selection); |
80
|
|
|
$value = $this->defineSelectionValue($selection); |
81
|
|
|
|
82
|
|
|
$radio = $this->createSelectionRadio($selection) |
83
|
|
|
->setChecked($this->isSelectionSelected($value)) |
84
|
|
|
->setName($this->name) |
85
|
|
|
->setValue($value) |
86
|
|
|
->setId($id); |
87
|
|
|
|
88
|
|
|
$label = $this->createSelectionLabel($selection)->setFor($id); |
89
|
|
|
|
90
|
|
|
$html .= $radio . $label; |
91
|
|
|
$html .= $this->isInline ? ' ' : '<br>'; |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
return $html; |
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
/** |
98
|
|
|
* |
99
|
|
|
*/ |
100
|
|
|
protected function createSelectionRadio($selection): Radio |
|
|
|
|
101
|
|
|
{ |
102
|
|
|
return new Radio(); |
103
|
|
|
} |
104
|
|
|
} |
105
|
|
|
|
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.