1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace kalanis\kw_forms\Controls; |
4
|
|
|
|
5
|
|
|
|
6
|
|
|
use kalanis\kw_forms\Interfaces\IOriginalValue; |
7
|
|
|
|
8
|
|
|
|
9
|
|
|
/** |
10
|
|
|
* Class Radio |
11
|
|
|
* @package kalanis\kw_forms\Controls |
12
|
|
|
* Render input for selecting by radio checkbox |
13
|
|
|
*/ |
14
|
|
|
class Radio extends AControl implements IOriginalValue |
15
|
|
|
{ |
16
|
|
|
use TChecked; |
17
|
|
|
|
18
|
|
|
protected string $templateInput = '<input type="radio" value="%1$s"%2$s />'; |
19
|
|
|
|
20
|
|
|
/**3 |
21
|
|
|
* @param string $alias |
22
|
|
|
* @param string|int|float|null $value |
23
|
|
|
* @param string $label |
24
|
|
|
* @param string $checked |
25
|
|
|
* @return $this |
26
|
|
|
*/ |
27
|
2 |
|
public function set(string $alias, $value = null, string $label = '', $checked = ''): self |
28
|
|
|
{ |
29
|
2 |
|
$this->setEntry($alias, $value, $label); |
30
|
2 |
|
$this->setChecked($checked); |
31
|
2 |
|
$this->setAttribute('id', $this->getKey()); |
32
|
2 |
|
return $this; |
33
|
|
|
} |
34
|
|
|
|
35
|
2 |
|
protected function fillTemplate(): string |
36
|
|
|
{ |
37
|
2 |
|
return '%2$s %1$s'; |
38
|
|
|
} |
39
|
|
|
|
40
|
2 |
|
public function getOriginalValue() |
41
|
|
|
{ |
42
|
2 |
|
return $this->originalValue; |
43
|
|
|
} |
44
|
|
|
|
45
|
2 |
|
public function renderInput($attributes = null): string |
46
|
|
|
{ |
47
|
2 |
|
$this->fillParent(); |
48
|
2 |
|
$this->addAttributes($attributes); |
49
|
2 |
|
if (!($this->parent instanceof RadioSet)) { |
50
|
1 |
|
$this->setAttribute('name', $this->getKey()); |
51
|
|
|
} |
52
|
2 |
|
return $this->wrapIt(sprintf($this->templateInput, $this->escaped(strval($this->getOriginalValue())), $this->renderAttributes(), $this->renderChildren()), $this->wrappersInput); |
53
|
|
|
} |
54
|
|
|
|
55
|
2 |
|
public function renderLabel($attributes = []): string |
56
|
|
|
{ |
57
|
2 |
|
$this->fillParent(); |
58
|
2 |
|
return parent::renderLabel($attributes); |
59
|
|
|
} |
60
|
|
|
|
61
|
2 |
|
protected function fillParent(): void |
62
|
|
|
{ |
63
|
2 |
|
if ($this->parent instanceof RadioSet) { |
64
|
1 |
|
$this->setAttribute('name', strval($this->parent->getAttribute('name'))); |
|
|
|
|
65
|
1 |
|
$this->setAttribute('id', $this->parent->getKey() . '_' . strval($this->getOriginalValue())); |
66
|
|
|
} |
67
|
2 |
|
} |
68
|
|
|
} |
69
|
|
|
|
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.