AllowMultiple.php
4 years ago
HasDefaultValue.php
4 years ago
HasEmailTag.php
4 years ago
HasHelpText.php
4 years ago
HasLabel.php
4 years ago
HasMaxLength.php
4 years ago
HasMinLength.php
4 years ago
HasName.php
4 years ago
HasNodes.php
4 years ago
HasOptions.php
4 years ago
HasPlaceholder.php
4 years ago
HasType.php
4 years ago
HasVisibilityConditions.php
4 years ago
InsertNode.php
4 years ago
IsReadOnly.php
4 years ago
IsRequired.php
4 years ago
Macroable.php
4 years ago
MoveNode.php
4 years ago
MoveNodeProxy.php
4 years ago
NameCollision.php
4 years ago
RemoveNode.php
4 years ago
SerializeAsJson.php
4 years ago
ShowInReceipt.php
4 years ago
StoreAsMeta.php
4 years ago
ValidationRules.php
4 years ago
WalkNodes.php
4 years ago
HasNodes.php
81 lines
| 1 | <?php |
| 2 | |
| 3 | namespace Give\Framework\FieldsAPI\Concerns; |
| 4 | |
| 5 | use Give\Framework\FieldsAPI\Contracts\Collection; |
| 6 | use Give\Framework\FieldsAPI\Contracts\Node; |
| 7 | use Give\Framework\FieldsAPI\Field; |
| 8 | |
| 9 | trait HasNodes |
| 10 | { |
| 11 | |
| 12 | /** @var Node[] */ |
| 13 | protected $nodes = []; |
| 14 | |
| 15 | /** |
| 16 | * {@inheritdoc} |
| 17 | */ |
| 18 | public function getNodeIndexByName($name) |
| 19 | { |
| 20 | foreach ($this->nodes as $index => $node) { |
| 21 | if ($node->getName() === $name) { |
| 22 | return $index; |
| 23 | } |
| 24 | } |
| 25 | |
| 26 | return false; |
| 27 | } |
| 28 | |
| 29 | /** |
| 30 | * {@inheritdoc} |
| 31 | */ |
| 32 | public function getNodeByName($name) |
| 33 | { |
| 34 | foreach ($this->nodes as $node) { |
| 35 | if ($node->getName() === $name) { |
| 36 | return $node; |
| 37 | } |
| 38 | if ($node instanceof Collection) { |
| 39 | return $node->getNodeByName($name); |
| 40 | } |
| 41 | } |
| 42 | |
| 43 | return false; |
| 44 | } |
| 45 | |
| 46 | /** |
| 47 | * {@inheritdoc} |
| 48 | */ |
| 49 | public function all() |
| 50 | { |
| 51 | return $this->nodes; |
| 52 | } |
| 53 | |
| 54 | /** |
| 55 | * {@inheritdoc} |
| 56 | */ |
| 57 | public function getFields() |
| 58 | { |
| 59 | $fields = []; |
| 60 | |
| 61 | foreach ($this->nodes as $node) { |
| 62 | if ($node instanceof Field) { |
| 63 | $fields[] = $node; |
| 64 | } elseif ($node instanceof Collection) { |
| 65 | $fields = array_merge($fields, $node->getFields()); |
| 66 | } |
| 67 | } |
| 68 | |
| 69 | return $fields; |
| 70 | } |
| 71 | |
| 72 | /** |
| 73 | * {@inheritdoc} |
| 74 | */ |
| 75 | public function count() |
| 76 | { |
| 77 | return count($this->nodes); |
| 78 | } |
| 79 | |
| 80 | } |
| 81 |