PluginProbe
Packeta / 2.1
Packeta v2.1
2.3.2 2.3.1 trunk 1.2.2 1.2.3 1.2.4 1.2.5 1.2.6 1.3.0 1.3.1 1.3.2 1.4 1.4.1 1.4.2 1.4.3 1.5.0 1.5.1 1.5.2 1.5.3 1.5.4 1.6.0 1.6.1 1.6.2 1.6.3 1.6.4 All 56 releases
packeta / deps / nette / forms / src / Forms / Controls / Checkbox.php

Checkbox.php in Packeta 2.1, at deps/nette/forms/src/Forms/Controls/Checkbox.php

79 lines 2.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /**
4 * This file is part of the Nette Framework (https://nette.org)
5 * Copyright (c) 2004 David Grudl (https://davidgrudl.com)
6 */
7 declare (strict_types=1);
8 namespace Packetery\Nette\Forms\Controls;
9
10 use Packetery\Nette;
11 use Packetery\Nette\Utils\Html;
12 /**
13 * Check box control. Allows the user to select a true or false condition.
14 */
15 class Checkbox extends BaseControl
16 {
17 /** @var Html wrapper element template */
18 private $container;
19 /**
20 * @param string|object $label
21 */
22 public function __construct($label = null)
23 {
24 parent::__construct($label);
25 $this->control->type = 'checkbox';
26 $this->container = Html::el();
27 $this->setOption('type', 'checkbox');
28 }
29 /**
30 * Sets control's value.
31 * @return static
32 * @internal
33 */
34 public function setValue($value)
35 {
36 if (!\is_scalar($value) && $value !== null) {
37 throw new \Packetery\Nette\InvalidArgumentException(\sprintf("Value must be scalar or null, %s given in field '%s'.", \gettype($value), $this->name));
38 }
39 $this->value = (bool) $value;
40 return $this;
41 }
42 public function isFilled() : bool
43 {
44 return $this->getValue() !== \false;
45 // back compatibility
46 }
47 public function getControl() : Html
48 {
49 return $this->container->setHtml($this->getLabelPart()->insert(0, $this->getControlPart()));
50 }
51 /**
52 * Bypasses label generation.
53 */
54 public function getLabel($caption = null)
55 {
56 return null;
57 }
58 public function getControlPart() : Html
59 {
60 return parent::getControl()->checked($this->value);
61 }
62 public function getLabelPart() : Html
63 {
64 return parent::getLabel();
65 }
66 /**
67 * Returns container HTML element template.
68 */
69 public function getContainerPrototype() : Html
70 {
71 return $this->container;
72 }
73 /** @deprecated use getContainerPrototype() */
74 public function getSeparatorPrototype() : Html
75 {
76 return $this->container;
77 }
78 }
79