Concerns
3 years ago
Conditions
4 years ago
Contracts
3 years ago
Exceptions
3 years ago
Facades
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
3 years ago
Form.php
3 years ago
Group.php
3 years ago
Hidden.php
4 years ago
Html.php
4 years ago
Option.php
3 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
Group.php
78 lines
| 1 | <?php |
| 2 | |
| 3 | namespace Give\Framework\FieldsAPI; |
| 4 | |
| 5 | use Give\Framework\FieldsAPI\Contracts\Collection; |
| 6 | use Give\Framework\FieldsAPI\Contracts\Node; |
| 7 | |
| 8 | /** |
| 9 | * @since 2.12.0 |
| 10 | * @since 2.13.0 Support visibility conditions |
| 11 | * @since 2.22.0 Add TapNode trait |
| 12 | */ |
| 13 | class Group implements Node, Collection |
| 14 | { |
| 15 | use Concerns\HasName; |
| 16 | use Concerns\HasNodes; |
| 17 | use Concerns\HasType; |
| 18 | use Concerns\HasVisibilityConditions; |
| 19 | use Concerns\InsertNode; |
| 20 | use Concerns\MoveNode; |
| 21 | use Concerns\NameCollision; |
| 22 | use Concerns\RemoveNode; |
| 23 | use Concerns\SerializeAsJson; |
| 24 | use Concerns\TapNode; |
| 25 | use Concerns\WalkNodes; |
| 26 | |
| 27 | /** |
| 28 | * @since 2.12.2 |
| 29 | */ |
| 30 | const TYPE = 'group'; |
| 31 | |
| 32 | /** |
| 33 | * @since 2.12.0 |
| 34 | * @since 2.23.1 Make constructor final to avoid unsafe usage of `new static()`. |
| 35 | * |
| 36 | * @param $name |
| 37 | */ |
| 38 | final public function __construct($name) |
| 39 | { |
| 40 | $this->name = $name; |
| 41 | } |
| 42 | |
| 43 | /** |
| 44 | * @inheritDoc |
| 45 | */ |
| 46 | public function getNodeType(): string |
| 47 | { |
| 48 | return 'group'; |
| 49 | } |
| 50 | |
| 51 | /** |
| 52 | * @since 2.12.0 |
| 53 | * |
| 54 | * @param $name |
| 55 | * |
| 56 | * @return static |
| 57 | */ |
| 58 | public static function make($name) |
| 59 | { |
| 60 | return new static($name); |
| 61 | } |
| 62 | |
| 63 | /** |
| 64 | * Gives th ability to fluently "tap" a specific node within the group. This is useful when fluently calling methods |
| 65 | * on the group, and making a change to a specific node without breaking the fluency. |
| 66 | * |
| 67 | * @since 2.22.0 |
| 68 | * |
| 69 | * @return $this |
| 70 | */ |
| 71 | public function tapNode(string $name, callable $callback) |
| 72 | { |
| 73 | $callback($this->getNodeByName($name)); |
| 74 | |
| 75 | return $this; |
| 76 | } |
| 77 | } |
| 78 |