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