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
MoveNodeProxy.php
55 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 | |
| 15 | /** @var Collection */ |
| 16 | protected $collection; |
| 17 | |
| 18 | /** @var Node */ |
| 19 | protected $targetNode; |
| 20 | |
| 21 | /** |
| 22 | * @param Collection $collection |
| 23 | */ |
| 24 | public function __construct(Collection $collection) |
| 25 | { |
| 26 | $this->collection = $collection; |
| 27 | } |
| 28 | |
| 29 | /** |
| 30 | * @param Node $node |
| 31 | */ |
| 32 | public function move($node) |
| 33 | { |
| 34 | $this->targetNode = $node; |
| 35 | } |
| 36 | |
| 37 | /** |
| 38 | * @param string $name The name of the node after which the target node should be inserted. |
| 39 | */ |
| 40 | public function after($name) |
| 41 | { |
| 42 | $this->collection->remove($this->targetNode->getName()); |
| 43 | $this->collection->insertAfter($name, $this->targetNode); |
| 44 | } |
| 45 | |
| 46 | /** |
| 47 | * @param string $name The name of the node before which the target node should be inserted. |
| 48 | */ |
| 49 | public function before($name) |
| 50 | { |
| 51 | $this->collection->remove($this->targetNode->getName()); |
| 52 | $this->collection->insertBefore($name, $this->targetNode); |
| 53 | } |
| 54 | } |
| 55 |