delboy1978uk /
form
| 1 | <?php |
||||
| 2 | |||||
| 3 | declare(strict_types=1); |
||||
| 4 | |||||
| 5 | namespace Del\Form\Field; |
||||
| 6 | |||||
| 7 | use Del\Form\Renderer\Field\CheckboxRender; |
||||
| 8 | use Del\Form\Traits\CanRenderInlineTrait; |
||||
| 9 | use Del\Form\Traits\HasOptionsTrait; |
||||
| 10 | |||||
| 11 | class CheckBox extends FieldAbstract implements ArrayValueInterface |
||||
| 12 | { |
||||
| 13 | |||||
| 14 | use CanRenderInlineTrait; |
||||
| 15 | use HasOptionsTrait; |
||||
| 16 | |||||
| 17 | /* |
||||
| 18 | * We end up ignoring this during rendering Checkboxes, see the renderer for info |
||||
| 19 | */ |
||||
| 20 | 8 | public function getTag(): string |
|||
| 21 | { |
||||
| 22 | 8 | return 'div'; |
|||
| 23 | } |
||||
| 24 | |||||
| 25 | 12 | public function init(): void |
|||
| 26 | { |
||||
| 27 | 12 | $this->setValue([]); |
|||
|
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||||
| 28 | 12 | $this->setRenderInline(false); |
|||
| 29 | 12 | $this->setRenderer(new CheckboxRender()); |
|||
| 30 | } |
||||
| 31 | |||||
| 32 | /** |
||||
| 33 | * @param $key |
||||
| 34 | */ |
||||
| 35 | 2 | public function checkValue($key): void |
|||
| 36 | { |
||||
| 37 | 2 | $values = $this->getValue(); |
|||
| 38 | 2 | $values[$key] = true; |
|||
| 39 | 2 | $this->setValue($values); |
|||
| 40 | } |
||||
| 41 | |||||
| 42 | /** |
||||
| 43 | * @param $key |
||||
| 44 | */ |
||||
| 45 | 1 | public function uncheckValue($key): void |
|||
| 46 | { |
||||
| 47 | 1 | $value = $this->getValue(); |
|||
| 48 | |||||
| 49 | 1 | if (is_array($value) && in_array($key, $value, true)) { |
|||
| 50 | 1 | $index = array_search($key, $value, true); |
|||
| 51 | 1 | unset($value[$index]); |
|||
| 52 | 1 | $this->setValue($value); |
|||
|
0 ignored issues
–
show
$value of type array is incompatible with the type string expected by parameter $value of Del\Form\Field\FieldAbstract::setValue().
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||
| 53 | } else { |
||||
| 54 | 1 | $this->setValue(null); |
|||
| 55 | } |
||||
| 56 | } |
||||
| 57 | } |
||||
| 58 |