/
MoveInto.php
104 lines (88 loc) · 3.36 KB
/
MoveInto.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
<?php
declare(strict_types=1);
namespace Neos\Neos\Ui\Domain\Model\Changes;
/*
* This file is part of the Neos.Neos.Ui package.
*
* (c) Contributors of the Neos Project - www.neos.io
*
* This package is Open Source Software. For the full copyright and license
* information, please view the LICENSE file which was distributed with this
* source code.
*/
use Neos\ContentRepository\Core\Feature\NodeMove\Command\MoveNodeAggregate;
use Neos\ContentRepository\Core\Projection\ContentGraph\Node;
use Neos\ContentRepository\Core\Feature\NodeMove\Dto\RelationDistributionStrategy;
use Neos\Neos\Ui\Domain\Model\Feedback\Operations\RemoveNode;
use Neos\Neos\Ui\Domain\Model\Feedback\Operations\UpdateNodeInfo;
class MoveInto extends AbstractStructuralChange
{
protected ?string $parentContextPath;
public function setParentContextPath(string $parentContextPath): void
{
$this->parentContextPath = $parentContextPath;
}
public function getParentNode(): ?Node
{
if ($this->parentContextPath === null) {
return null;
}
return $this->nodeService->getNodeFromContextPath(
$this->parentContextPath,
$this->getSubject()->subgraphIdentity->contentRepositoryId
);
}
/**
* Get the insertion mode (before|after|into) that is represented by this change
*/
public function getMode(): string
{
return 'into';
}
/**
* Checks whether this change can be applied to the subject
*/
public function canApply(): bool
{
if (is_null($this->subject)) {
return false;
}
$parent = $this->getParentNode();
$nodeType = $this->subject->nodeType;
return $parent && $this->isNodeTypeAllowedAsChildNode($parent, $nodeType);
}
/**
* Applies this change
*/
public function apply(): void
{
// "parentNode" is the node where the $subject should be moved INTO
$parentNode = $this->getParentNode();
// "subject" is the to-be-moved node
$subject = $this->subject;
if ($this->canApply() && $parentNode && $subject) {
$otherParent = $this->contentRepositoryRegistry->subgraphForNode($subject)
->findParentNode($subject->nodeAggregateId);
$hasEqualParentNode = $otherParent && $otherParent->nodeAggregateId
->equals($parentNode->nodeAggregateId);
$contentRepository = $this->contentRepositoryRegistry->get($subject->subgraphIdentity->contentRepositoryId);
$contentRepository->handle(
new MoveNodeAggregate(
$subject->subgraphIdentity->contentStreamId,
$subject->subgraphIdentity->dimensionSpacePoint,
$subject->nodeAggregateId,
$hasEqualParentNode ? null : $parentNode->nodeAggregateId,
null,
null,
RelationDistributionStrategy::STRATEGY_GATHER_ALL
)
)->block();
$updateParentNodeInfo = new UpdateNodeInfo();
$updateParentNodeInfo->setNode($parentNode);
$this->feedbackCollection->add($updateParentNodeInfo);
$removeNode = new RemoveNode($subject, $parentNode);
$this->feedbackCollection->add($removeNode);
$this->finish($subject);
}
}
}