Concerns
4 years ago
Conditions
4 years ago
Contracts
4 years ago
Exceptions
4 years ago
Facades
4 years ago
FormFieldMediator
4 years ago
Checkbox.php
4 years ago
Date.php
4 years ago
Element.php
4 years ago
Email.php
4 years ago
Factory.php
4 years ago
Field.php
4 years ago
File.php
4 years ago
Form.php
4 years ago
Group.php
4 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
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
65 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 | */ |
| 14 | abstract class Field implements Node |
| 15 | { |
| 16 | |
| 17 | use Concerns\HasDefaultValue; |
| 18 | use Concerns\HasName; |
| 19 | use Concerns\HasType; |
| 20 | use Concerns\HasVisibilityConditions; |
| 21 | use Concerns\IsReadOnly; |
| 22 | use Concerns\IsRequired; |
| 23 | use Concerns\Macroable; |
| 24 | use Concerns\SerializeAsJson; |
| 25 | |
| 26 | /** @var ValidationRules */ |
| 27 | protected $validationRules; |
| 28 | |
| 29 | /** |
| 30 | * @since 2.12.0 |
| 31 | * |
| 32 | * @param string $name |
| 33 | * |
| 34 | * @throws EmptyNameException |
| 35 | */ |
| 36 | public function __construct($name) |
| 37 | { |
| 38 | if ( ! $name) { |
| 39 | throw new EmptyNameException(); |
| 40 | } |
| 41 | |
| 42 | $this->name = $name; |
| 43 | $this->validationRules = new ValidationRules(); |
| 44 | } |
| 45 | |
| 46 | /** |
| 47 | * Create a named field. |
| 48 | * |
| 49 | * @since 2.12.0 |
| 50 | * |
| 51 | * @param string $name |
| 52 | * |
| 53 | * @return static |
| 54 | * @throws EmptyNameException |
| 55 | */ |
| 56 | public static function make($name) |
| 57 | { |
| 58 | if ( ! $name) { |
| 59 | throw new EmptyNameException(); |
| 60 | } |
| 61 | |
| 62 | return new static($name); |
| 63 | } |
| 64 | } |
| 65 |