CheckboxGroup.php
54 lines
| 1 | <?php |
| 2 | |
| 3 | namespace Give\Framework\FieldsAPI\LegacyNodes; |
| 4 | |
| 5 | use Give\Framework\FieldsAPI\Concerns; |
| 6 | use Give\Framework\FieldsAPI\Field; |
| 7 | |
| 8 | /** |
| 9 | * This class is a legacy node for the old Form Field Manager Checkbox field. It should not be used in any other context |
| 10 | * and will be eventually be removed. |
| 11 | * |
| 12 | * @since 2.28.0 Moved here to discourage future use |
| 13 | * @since 2.12.0 |
| 14 | */ |
| 15 | class CheckboxGroup extends Field |
| 16 | { |
| 17 | use Concerns\HasEmailTag; |
| 18 | use Concerns\HasHelpText; |
| 19 | use Concerns\HasLabel; |
| 20 | use Concerns\HasOptions; |
| 21 | use Concerns\HasPlaceholder; |
| 22 | |
| 23 | const TYPE = 'legacy-checkbox-group'; |
| 24 | |
| 25 | /** |
| 26 | * Helper for marking the checkbox as checked by default |
| 27 | * |
| 28 | * @since 2.12.0 |
| 29 | * |
| 30 | * @param bool|callable $isChecked |
| 31 | * |
| 32 | * @return $this |
| 33 | */ |
| 34 | public function checked($isChecked = true) |
| 35 | { |
| 36 | $default = is_callable($isChecked) ? $isChecked() : $isChecked; |
| 37 | $this->defaultValue((bool)$default); |
| 38 | |
| 39 | return $this; |
| 40 | } |
| 41 | |
| 42 | /** |
| 43 | * Returns whether the checkbox is checked by default |
| 44 | * |
| 45 | * @since 2.12.0 |
| 46 | * |
| 47 | * @return bool |
| 48 | */ |
| 49 | public function isChecked() |
| 50 | { |
| 51 | return (bool)$this->defaultValue; |
| 52 | } |
| 53 | } |
| 54 |