-
-
Notifications
You must be signed in to change notification settings - Fork 139
/
Copy pathAbstractMove.php
90 lines (82 loc) · 2.96 KB
/
AbstractMove.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
<?php
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\Domain\Model\Node;
use Neos\ContentRepository\Domain\Model\NodeInterface;
use Neos\ContentRepository\Domain\Service as ContentRepository;
use Neos\Neos\Ui\Domain\Model\Feedback\Operations\RemoveNode;
use Neos\Flow\Annotations as Flow;
use Neos\Neos\Ui\Domain\Model\Feedback\Operations\UpdateNodePath;
use Neos\Neos\Ui\Domain\Model\Feedback\Operations\Redirect;
abstract class AbstractMove extends AbstractStructuralChange
{
/**
* @Flow\Inject
* @var ContentRepository\NodeServiceInterface
*/
protected $contentRepositoryNodeService;
/**
* Perform finish tasks - needs to be called from inheriting class on `apply`
*
* @param NodeInterface $node
* @return void
*/
protected function finish(NodeInterface $node)
{
if ($node->getContextPath() !== $this->getSubject()->getContextPath()) {
$updateNodePath = new UpdateNodePath();
$updateNodePath->setOldContextPath($node->getContextPath());
$updateNodePath->setNewContextPath($this->getSubject()->getContextPath());
$this->feedbackCollection->add($updateNodePath);
}
if ($this->getSubject()->getNodeType()->isOfType('Neos.Neos:Document')) {
$redirect = new Redirect();
$redirect->setNode($this->getSubject());
$this->feedbackCollection->add($redirect);
}
// $this->getSubject() is the moved node at the NEW location!
parent::finish($this->getSubject());
}
protected static function cloneNodeWithNodeData(NodeInterface $node)
{
if ($node instanceof Node) {
$originalNode = $node;
$node = clone $originalNode;
$node->setNodeData(clone $originalNode->getNodeData());
return $node;
} else {
// do a best-effort clone
return clone $node;
}
}
/**
* Generate a unique node name for the copied node
*
* @param NodeInterface $parentNode
* @return string
*/
protected function generateUniqueNodeName(NodeInterface $parentNode)
{
return $this->contentRepositoryNodeService
->generateUniqueNodeName($parentNode->getPath());
}
/**
* Returns true if the current name of $node is "free" below $parentNode
*
* @param NodeInterface $parentNode
* @param NodeInterface $node
* @return bool
*/
protected function nodeNameAvailableBelowNode(NodeInterface $parentNode, NodeInterface $node)
{
return $this->contentRepositoryNodeService->nodePathAvailableForNode($parentNode->getPath() . '/' . $node->getName(), $node);
}
}