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
MoveNodeProxy.php
50 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 | |
| 8 | /** |
| 9 | * Stores an reference to the node being moved for a fluent API. |
| 10 | * Combines `remove` and `insert*` methods for a declarative API. |
| 11 | */ |
| 12 | class MoveNodeProxy { |
| 13 | |
| 14 | /** @var Collection */ |
| 15 | protected $collection; |
| 16 | |
| 17 | /** @var Node */ |
| 18 | protected $targetNode; |
| 19 | |
| 20 | /** |
| 21 | * @param Collection $collection |
| 22 | */ |
| 23 | public function __construct( Collection $collection ) { |
| 24 | $this->collection = $collection; |
| 25 | } |
| 26 | |
| 27 | /** |
| 28 | * @param Node $node |
| 29 | */ |
| 30 | public function move( $node ) { |
| 31 | $this->targetNode = $node; |
| 32 | } |
| 33 | |
| 34 | /** |
| 35 | * @param string $name The name of the node after which the target node should be inserted. |
| 36 | */ |
| 37 | public function after( $name ) { |
| 38 | $this->collection->remove( $this->targetNode->getName() ); |
| 39 | $this->collection->insertAfter( $name, $this->targetNode ); |
| 40 | } |
| 41 | |
| 42 | /** |
| 43 | * @param string $name The name of the node before which the target node should be inserted. |
| 44 | */ |
| 45 | public function before( $name ) { |
| 46 | $this->collection->remove( $this->targetNode->getName() ); |
| 47 | $this->collection->insertBefore( $name, $this->targetNode ); |
| 48 | } |
| 49 | } |
| 50 |