PluginProbe
GiveWP – Donation Plugin and Fundraising Platform / 2.17.0
GiveWP – Donation Plugin and Fundraising Platform v2.17.0
4.16.8 4.16.7.2 4.16.7.1 4.16.7 4.16.6.1 4.16.6 4.16.5.1 4.16.5 4.16.4 4.16.3 4.16.2 4.16.1 4.16.0 4.15.5 4.15.4 4.15.3 4.15.2 4.15.1 4.15.0 2.3.0 2.3.1 2.3.2 2.30.0 2.31.0 2.31.1 All 253 releases
give / src / Framework / FieldsAPI / Concerns / MoveNodeProxy.php
MoveNodeProxy.php
50 lines 1.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
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