AllowMultiple.php
4 years ago
HasDefaultValue.php
4 years ago
HasEmailTag.php
3 years ago
HasHelpText.php
4 years ago
HasLabel.php
3 years ago
HasMaxLength.php
3 years ago
HasMinLength.php
3 years ago
HasName.php
3 years ago
HasNodes.php
3 years ago
HasOptions.php
4 years ago
HasPlaceholder.php
4 years ago
HasType.php
3 years ago
HasVisibilityConditions.php
3 years ago
InsertNode.php
3 years ago
IsReadOnly.php
4 years ago
IsRequired.php
3 years ago
Macroable.php
4 years ago
MoveNode.php
3 years ago
MoveNodeProxy.php
4 years ago
NameCollision.php
3 years ago
RemoveNode.php
3 years ago
SerializeAsJson.php
3 years ago
ShowInAdmin.php
3 years ago
ShowInReceipt.php
3 years ago
StoreAsMeta.php
3 years ago
TapNode.php
3 years ago
WalkNodes.php
4 years ago
HasMaxLength.php
50 lines
| 1 | <?php |
| 2 | |
| 3 | namespace Give\Framework\FieldsAPI\Concerns; |
| 4 | |
| 5 | |
| 6 | use Give\Vendors\StellarWP\Validation\Rules\Max; |
| 7 | |
| 8 | /** |
| 9 | * @since 2.24.0 update to new validation system |
| 10 | * @since 2.14.0 |
| 11 | */ |
| 12 | trait HasMaxLength |
| 13 | { |
| 14 | /** |
| 15 | * Set the value’s maximum length. |
| 16 | * |
| 17 | * @since 2.24.0 update to use the new validation system |
| 18 | * @since 2.14.0 |
| 19 | */ |
| 20 | public function maxLength(int $maxLength): self |
| 21 | { |
| 22 | if ( $this->hasRule('max') ) { |
| 23 | /** @var Max $rule */ |
| 24 | $rule = $this->getRule('max'); |
| 25 | $rule->size($maxLength); |
| 26 | } |
| 27 | |
| 28 | $this->rules("max:$maxLength"); |
| 29 | |
| 30 | return $this; |
| 31 | } |
| 32 | |
| 33 | /** |
| 34 | * Get the value’s maximum length. |
| 35 | * |
| 36 | * @since 2.24.0 update to use the new validation system |
| 37 | * @since 2.14.0 |
| 38 | * |
| 39 | * @return int|null |
| 40 | */ |
| 41 | public function getMaxLength() |
| 42 | { |
| 43 | if ( !$this->hasRule('max') ) { |
| 44 | return null; |
| 45 | } |
| 46 | |
| 47 | return $this->getRule('max')->getSize(); |
| 48 | } |
| 49 | } |
| 50 |