Actions
2 years ago
Concerns
2 years ago
Contracts
3 years ago
Exceptions
2 years ago
Facades
4 years ago
LegacyNodes
3 years ago
Properties
1 year ago
ValueObjects
2 years ago
Amount.php
2 years ago
Authentication.php
1 year ago
BillingAddress.php
2 years ago
Checkbox.php
2 years ago
Consent.php
2 years ago
Date.php
1 year ago
DonationAmount.php
2 years ago
DonationForm.php
2 years ago
DonationSummary.php
2 years ago
Element.php
3 years ago
Email.php
2 years ago
Factory.php
4 years ago
Field.php
2 years ago
File.php
1 year ago
Form.php
3 years ago
Group.php
3 years ago
Hidden.php
3 years ago
Honeypot.php
1 year ago
Html.php
3 years ago
MultiSelect.php
1 year ago
Name.php
2 years ago
Option.php
2 years ago
Paragraph.php
2 years ago
Password.php
2 years ago
PaymentGateways.php
2 years ago
Phone.php
1 year ago
Radio.php
2 years ago
Section.php
2 years ago
SecurityChallenge.php
1 year ago
Select.php
2 years ago
Text.php
2 years ago
Textarea.php
2 years ago
Types.php
2 years ago
Url.php
2 years ago
Field.php
81 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\Framework\FieldsAPI\ValueObjects\PersistenceScope; |
| 8 | use Give\Vendors\StellarWP\Validation\Concerns\HasValidationRules; |
| 9 | |
| 10 | /** |
| 11 | * @since 2.27.3 add ShowInAdmin, ShowInReceipt, StoreAsMeta |
| 12 | * @since 2.17.0 allow fields to be macroable |
| 13 | * @since 2.12.0 |
| 14 | * @since 2.13.0 Support visibility conditions |
| 15 | * @since 2.22.0 Add TapNode trait |
| 16 | */ |
| 17 | abstract class Field implements Node |
| 18 | { |
| 19 | use Concerns\HasDefaultValue; |
| 20 | use Concerns\HasName; |
| 21 | use Concerns\HasType; |
| 22 | use Concerns\HasPersistence; |
| 23 | use Concerns\IsReadOnly; |
| 24 | use Concerns\IsRequired; |
| 25 | use Concerns\Macroable; |
| 26 | use Concerns\SerializeAsJson; |
| 27 | use Concerns\TapNode; |
| 28 | use Concerns\ShowInAdmin; |
| 29 | use Concerns\ShowInReceipt; |
| 30 | use Concerns\HasVisibilityConditions { |
| 31 | Concerns\HasVisibilityConditions::__construct as private __visibilityConditionsConstruct; |
| 32 | } |
| 33 | use HasValidationRules { |
| 34 | HasValidationRules::__construct as private __validationRulesConstruct; |
| 35 | } |
| 36 | |
| 37 | /** |
| 38 | * @since 2.32.0 sets the default scope to donation |
| 39 | * @since 2.23.1 make constructor final to avoid unsafe usage of `new static()`. |
| 40 | * @since 2.12.0 |
| 41 | * |
| 42 | * @throws EmptyNameException |
| 43 | */ |
| 44 | final public function __construct(string $name) |
| 45 | { |
| 46 | if (!$name) { |
| 47 | throw new EmptyNameException(); |
| 48 | } |
| 49 | |
| 50 | $this->name = $name; |
| 51 | $this->scope = PersistenceScope::donation(); |
| 52 | $this->__validationRulesConstruct(); |
| 53 | $this->__visibilityConditionsConstruct(); |
| 54 | } |
| 55 | |
| 56 | /** |
| 57 | * @inheritDoc |
| 58 | */ |
| 59 | public function getNodeType(): string |
| 60 | { |
| 61 | return 'field'; |
| 62 | } |
| 63 | |
| 64 | /** |
| 65 | * Create a named field. |
| 66 | * |
| 67 | * @since 2.12.0 |
| 68 | * |
| 69 | * @return static |
| 70 | * @throws EmptyNameException |
| 71 | */ |
| 72 | public static function make(string $name): self |
| 73 | { |
| 74 | if (!$name) { |
| 75 | throw new EmptyNameException(); |
| 76 | } |
| 77 | |
| 78 | return new static($name); |
| 79 | } |
| 80 | } |
| 81 |