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