AllowMultiple.php
4 years ago
HasDefaultValue.php
4 years ago
HasDescription.php
2 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
HasPersistence.php
2 years ago
HasPlaceholder.php
4 years ago
HasType.php
3 years ago
HasVisibilityConditions.php
2 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
2 years ago
RemoveNode.php
2 years ago
SerializeAsJson.php
3 years ago
ShowInAdmin.php
3 years ago
ShowInReceipt.php
2 years ago
TapNode.php
3 years ago
WalkNodes.php
4 years ago
WalkNodes.php
51 lines
| 1 | <?php |
| 2 | |
| 3 | namespace Give\Framework\FieldsAPI\Concerns; |
| 4 | |
| 5 | use Give\Framework\FieldsAPI\Contracts\Collection; |
| 6 | |
| 7 | /** |
| 8 | * A declarative iterator for each Node in the tree. |
| 9 | */ |
| 10 | trait WalkNodes |
| 11 | { |
| 12 | |
| 13 | /** |
| 14 | * @param callable $callback |
| 15 | * |
| 16 | * @return void |
| 17 | */ |
| 18 | public function walk(callable $callback) |
| 19 | { |
| 20 | $this->walkCollection($this, $callback); |
| 21 | } |
| 22 | |
| 23 | /** |
| 24 | * @param Collection $collection |
| 25 | * @param callable $callback |
| 26 | * |
| 27 | * @return void |
| 28 | */ |
| 29 | public function walkCollection(Collection $collection, callable $callback) |
| 30 | { |
| 31 | foreach ($collection->all() as $node) { |
| 32 | $callback($node); |
| 33 | if ($node instanceof Collection) { |
| 34 | $this->walkCollection($node, $callback); |
| 35 | } |
| 36 | } |
| 37 | } |
| 38 | |
| 39 | /** |
| 40 | * @param callable $callback |
| 41 | * |
| 42 | * @return void |
| 43 | */ |
| 44 | public function walkFields(callable $callback) |
| 45 | { |
| 46 | foreach ($this->getFields() as $field) { |
| 47 | $callback($field); |
| 48 | } |
| 49 | } |
| 50 | } |
| 51 |