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
Field.php
78 lines
| 1 | <?php |
| 2 | |
| 3 | namespace Give\Framework\FieldsAPI; |
| 4 | |
| 5 | use Give\Framework\FieldsAPI\Contracts\Node; |
| 6 | use Give\Framework\FieldsAPI\Exceptions\EmptyNameException; |
| 7 | use Give\Vendors\StellarWP\Validation\Concerns\HasValidationRules; |
| 8 | |
| 9 | /** |
| 10 | * @since 2.27.3 add ShowInAdmin, ShowInReceipt, StoreAsMeta |
| 11 | * @since 2.17.0 allow fields to be macroable |
| 12 | * @since 2.12.0 |
| 13 | * @since 2.13.0 Support visibility conditions |
| 14 | * @since 2.22.0 Add TapNode trait |
| 15 | */ |
| 16 | abstract class Field implements Node |
| 17 | { |
| 18 | use Concerns\HasDefaultValue; |
| 19 | use Concerns\HasName; |
| 20 | use Concerns\HasType; |
| 21 | use Concerns\IsReadOnly; |
| 22 | use Concerns\IsRequired; |
| 23 | use Concerns\Macroable; |
| 24 | use Concerns\SerializeAsJson; |
| 25 | use Concerns\TapNode; |
| 26 | use Concerns\ShowInAdmin; |
| 27 | use Concerns\ShowInReceipt; |
| 28 | use Concerns\StoreAsMeta; |
| 29 | use Concerns\HasVisibilityConditions { |
| 30 | Concerns\HasVisibilityConditions::__construct as private __visibilityConditionsConstruct; |
| 31 | } |
| 32 | use HasValidationRules { |
| 33 | HasValidationRules::__construct as private __validationRulesConstruct; |
| 34 | } |
| 35 | |
| 36 | /** |
| 37 | * @since 2.12.0 |
| 38 | * @since 2.23.1 Make constructor final to avoid unsafe usage of `new static()`. |
| 39 | * |
| 40 | * @throws EmptyNameException |
| 41 | */ |
| 42 | final public function __construct(string $name) |
| 43 | { |
| 44 | if (!$name) { |
| 45 | throw new EmptyNameException(); |
| 46 | } |
| 47 | |
| 48 | $this->name = $name; |
| 49 | $this->__validationRulesConstruct(); |
| 50 | $this->__visibilityConditionsConstruct(); |
| 51 | } |
| 52 | |
| 53 | /** |
| 54 | * @inheritDoc |
| 55 | */ |
| 56 | public function getNodeType(): string |
| 57 | { |
| 58 | return 'field'; |
| 59 | } |
| 60 | |
| 61 | /** |
| 62 | * Create a named field. |
| 63 | * |
| 64 | * @since 2.12.0 |
| 65 | * |
| 66 | * @return static |
| 67 | * @throws EmptyNameException |
| 68 | */ |
| 69 | public static function make(string $name): self |
| 70 | { |
| 71 | if (!$name) { |
| 72 | throw new EmptyNameException(); |
| 73 | } |
| 74 | |
| 75 | return new static($name); |
| 76 | } |
| 77 | } |
| 78 |