Actions
3 years ago
Concerns
3 years ago
Contracts
3 years ago
Exceptions
3 years ago
Facades
4 years ago
Checkbox.php
3 years ago
Date.php
3 years ago
Element.php
3 years ago
Email.php
3 years ago
Factory.php
4 years ago
Field.php
3 years ago
File.php
3 years ago
Form.php
3 years ago
Group.php
3 years ago
Hidden.php
3 years ago
Html.php
4 years ago
Option.php
3 years ago
Phone.php
3 years ago
Radio.php
3 years ago
Section.php
3 years ago
Select.php
3 years ago
Text.php
3 years ago
Textarea.php
3 years ago
Types.php
4 years ago
Url.php
3 years ago
Checkbox.php
47 lines
| 1 | <?php |
| 2 | |
| 3 | namespace Give\Framework\FieldsAPI; |
| 4 | |
| 5 | /** |
| 6 | * @since 2.12.0 |
| 7 | */ |
| 8 | class Checkbox extends Field |
| 9 | { |
| 10 | use Concerns\HasEmailTag; |
| 11 | use Concerns\HasHelpText; |
| 12 | use Concerns\HasLabel; |
| 13 | use Concerns\HasOptions; |
| 14 | use Concerns\HasPlaceholder; |
| 15 | |
| 16 | const TYPE = 'checkbox'; |
| 17 | |
| 18 | /** |
| 19 | * Helper for marking the checkbox as checked by default |
| 20 | * |
| 21 | * @since 2.12.0 |
| 22 | * |
| 23 | * @param bool|callable $isChecked |
| 24 | * |
| 25 | * @return $this |
| 26 | */ |
| 27 | public function checked($isChecked = true) |
| 28 | { |
| 29 | $default = is_callable($isChecked) ? $isChecked() : $isChecked; |
| 30 | $this->defaultValue((bool)$default); |
| 31 | |
| 32 | return $this; |
| 33 | } |
| 34 | |
| 35 | /** |
| 36 | * Returns whether the checkbox is checked by default |
| 37 | * |
| 38 | * @since 2.12.0 |
| 39 | * |
| 40 | * @return bool |
| 41 | */ |
| 42 | public function isChecked() |
| 43 | { |
| 44 | return (bool)$this->defaultValue; |
| 45 | } |
| 46 | } |
| 47 |