Concerns
3 years ago
Conditions
4 years ago
Contracts
3 years ago
Exceptions
3 years ago
Facades
4 years ago
FormFieldMediator
4 years ago
Checkbox.php
4 years ago
Date.php
4 years ago
Element.php
3 years ago
Email.php
4 years ago
Factory.php
4 years ago
Field.php
3 years ago
File.php
4 years ago
Form.php
3 years ago
Group.php
3 years ago
Hidden.php
4 years ago
Html.php
4 years ago
Option.php
4 years ago
Phone.php
4 years ago
Radio.php
4 years ago
Section.php
3 years ago
Select.php
4 years ago
Text.php
4 years ago
Textarea.php
4 years ago
Types.php
4 years ago
Url.php
4 years ago
Field.php
75 lines
| 1 | <?php |
| 2 | |
| 3 | namespace Give\Framework\FieldsAPI; |
| 4 | |
| 5 | use Give\Framework\FieldsAPI\Concerns\ValidationRules; |
| 6 | use Give\Framework\FieldsAPI\Contracts\Node; |
| 7 | use Give\Framework\FieldsAPI\Exceptions\EmptyNameException; |
| 8 | |
| 9 | /** |
| 10 | * @since 2.17.0 allow fields to be macroable |
| 11 | * @since 2.12.0 |
| 12 | * @since 2.13.0 Support visibility conditions |
| 13 | * @since 2.22.0 Add TapNode trait |
| 14 | */ |
| 15 | abstract class Field implements Node |
| 16 | { |
| 17 | |
| 18 | use Concerns\HasDefaultValue; |
| 19 | use Concerns\HasName; |
| 20 | use Concerns\HasType; |
| 21 | use Concerns\HasVisibilityConditions; |
| 22 | use Concerns\IsReadOnly; |
| 23 | use Concerns\IsRequired; |
| 24 | use Concerns\Macroable; |
| 25 | use Concerns\SerializeAsJson; |
| 26 | use Concerns\TapNode; |
| 27 | |
| 28 | /** @var ValidationRules */ |
| 29 | protected $validationRules; |
| 30 | |
| 31 | /** |
| 32 | * @since 2.12.0 |
| 33 | * |
| 34 | * @param string $name |
| 35 | * |
| 36 | * @throws EmptyNameException |
| 37 | */ |
| 38 | public function __construct($name) |
| 39 | { |
| 40 | if (!$name) { |
| 41 | throw new EmptyNameException(); |
| 42 | } |
| 43 | |
| 44 | $this->name = $name; |
| 45 | $this->validationRules = new ValidationRules(); |
| 46 | } |
| 47 | |
| 48 | /** |
| 49 | * @inheritDoc |
| 50 | */ |
| 51 | public function getNodeType(): string |
| 52 | { |
| 53 | return 'field'; |
| 54 | } |
| 55 | |
| 56 | /** |
| 57 | * Create a named field. |
| 58 | * |
| 59 | * @since 2.12.0 |
| 60 | * |
| 61 | * @param string $name |
| 62 | * |
| 63 | * @return static |
| 64 | * @throws EmptyNameException |
| 65 | */ |
| 66 | public static function make($name) |
| 67 | { |
| 68 | if (!$name) { |
| 69 | throw new EmptyNameException(); |
| 70 | } |
| 71 | |
| 72 | return new static($name); |
| 73 | } |
| 74 | } |
| 75 |