FieldAttributes.php
5 years ago
FieldDefaultValue.php
5 years ago
FieldEmailTag.php
5 years ago
FieldHelpText.php
5 years ago
FieldLabel.php
5 years ago
FieldOptions.php
5 years ago
FieldReadOnly.php
5 years ago
FieldReceipt.php
5 years ago
FieldRequired.php
5 years ago
FieldStoreAsMeta.php
5 years ago
FieldTypes.php
5 years ago
FieldRequired.php
33 lines
| 1 | <?php |
| 2 | |
| 3 | namespace Give\Framework\FieldsAPI\FormField; |
| 4 | |
| 5 | trait FieldRequired { |
| 6 | |
| 7 | /** @var bool */ |
| 8 | protected $required = false; |
| 9 | |
| 10 | /** |
| 11 | * @param bool $requried |
| 12 | * @return $this |
| 13 | */ |
| 14 | public function required( $required = true ) { |
| 15 | $this->required = $required; |
| 16 | return $this; |
| 17 | } |
| 18 | |
| 19 | /** |
| 20 | * @return bool |
| 21 | */ |
| 22 | public function isRequired() { |
| 23 | return $this->required; |
| 24 | } |
| 25 | |
| 26 | public function getRequiredError() { |
| 27 | return [ |
| 28 | 'error_id' => $this->name, |
| 29 | 'error_message' => __( 'Please enter a value for ' . $this->name, 'give' ), |
| 30 | ]; |
| 31 | } |
| 32 | } |
| 33 |