/
PluginViewTransformation.php
71 lines (65 loc) · 2.07 KB
/
PluginViewTransformation.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
<?php
namespace Neos\Neos\TYPO3CR\Transformations;
/*
* This file is part of the Neos.Neos 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\Flow\Annotations as Flow;
use Neos\ContentRepository\Domain\Model\NodeData;
use Neos\ContentRepository\Domain\Model\NodeInterface;
use Neos\ContentRepository\Domain\Repository\NodeDataRepository;
use Neos\ContentRepository\Migration\Transformations\AbstractTransformation;
/**
* Convert PluginViews references from node paths to identifiers
*/
class PluginViewTransformation extends AbstractTransformation
{
/**
* @Flow\Inject
* @var NodeDataRepository
*/
protected $nodeDataRepository;
/**
* @var boolean
*/
public $reverse = false;
/**
* @param NodeData $node
* @return boolean
*/
public function isTransformable(NodeData $node)
{
return true;
}
/**
* Change the property on the given node.
*
* @param NodeData $node
* @return NodeData
*/
public function execute(NodeData $node)
{
$reference = (string)$node->getProperty('plugin');
$workspace = $node->getWorkspace();
do {
if ($this->reverse === false && preg_match(NodeInterface::MATCH_PATTERN_PATH, $reference)) {
$pluginNode = $this->nodeDataRepository->findOneByPath($reference, $node->getWorkspace());
} else {
$pluginNode = $this->nodeDataRepository->findOneByIdentifier($reference, $node->getWorkspace());
}
if (isset($pluginNode)) {
break;
}
$workspace = $workspace->getBaseWorkspace();
} while ($workspace && $workspace->getName() !== 'live');
if (isset($pluginNode)) {
$node->setProperty('plugin', $this->reverse === false ? $pluginNode->getIdentifier() : $pluginNode->getPath());
}
return $node;
}
}