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
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
73 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 | /** @var Node[] */ |
| 12 | protected $nodes = []; |
| 13 | |
| 14 | /** |
| 15 | * {@inheritdoc} |
| 16 | */ |
| 17 | public function getNodeIndexByName( $name ) { |
| 18 | foreach ( $this->nodes as $index => $node ) { |
| 19 | if ( $node->getName() === $name ) { |
| 20 | return $index; |
| 21 | } |
| 22 | } |
| 23 | return false; |
| 24 | } |
| 25 | |
| 26 | /** |
| 27 | * {@inheritdoc} |
| 28 | */ |
| 29 | public function getNodeByName( $name ) { |
| 30 | foreach ( $this->nodes as $node ) { |
| 31 | if ( $node->getName() === $name ) { |
| 32 | return $node; |
| 33 | } |
| 34 | if ( $node instanceof Collection ) { |
| 35 | return $node->getNodeByName( $name ); |
| 36 | } |
| 37 | } |
| 38 | return false; |
| 39 | } |
| 40 | |
| 41 | /** |
| 42 | * {@inheritdoc} |
| 43 | */ |
| 44 | public function all() { |
| 45 | return $this->nodes; |
| 46 | } |
| 47 | |
| 48 | /** |
| 49 | * {@inheritdoc} |
| 50 | */ |
| 51 | public function getFields() { |
| 52 | $fields = []; |
| 53 | |
| 54 | foreach ( $this->nodes as $node ) { |
| 55 | if ( $node instanceof Field ) { |
| 56 | $fields[] = $node; |
| 57 | } elseif ( $node instanceof Collection ) { |
| 58 | $fields = array_merge( $fields, $node->getFields() ); |
| 59 | } |
| 60 | } |
| 61 | |
| 62 | return $fields; |
| 63 | } |
| 64 | |
| 65 | /** |
| 66 | * {@inheritdoc} |
| 67 | */ |
| 68 | public function count() { |
| 69 | return count( $this->nodes ); |
| 70 | } |
| 71 | |
| 72 | } |
| 73 |