-
-
Notifications
You must be signed in to change notification settings - Fork 219
/
NodeHelper.php
82 lines (76 loc) · 2.85 KB
/
NodeHelper.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
<?php
namespace Neos\Neos\Fusion\Helper;
/*
* 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\Eel\ProtectedContextAwareInterface;
use Neos\ContentRepository\Domain\Model\NodeInterface;
use Neos\Neos\Domain\Exception;
/**
* Eel helper for ContentRepository Nodes
*/
class NodeHelper implements ProtectedContextAwareInterface
{
/**
* Check if the given node is already a collection, find collection by nodePath otherwise, throw exception
* if no content collection could be found
*
* @param NodeInterface $node
* @param string $nodePath
* @return NodeInterface
* @throws Exception
*/
public function nearestContentCollection(NodeInterface $node, $nodePath)
{
$contentCollectionType = 'Neos.Neos:ContentCollection';
if ($node->getNodeType()->isOfType($contentCollectionType)) {
return $node;
} else {
if ((string)$nodePath === '') {
throw new Exception(sprintf('No content collection of type %s could be found in the current node and no node path was provided. You might want to configure the nodePath property with a relative path to the content collection.', $contentCollectionType), 1409300545);
}
$subNode = $node->getNode($nodePath);
if ($subNode !== null && $subNode->getNodeType()->isOfType($contentCollectionType)) {
return $subNode;
} else {
throw new Exception(sprintf('No content collection of type %s could be found in the current node (%s) or at the path "%s". You might want to adjust your node type configuration and create the missing child node through the "./flow node:repair --node-type %s" command.', $contentCollectionType, $node->getPath(), $nodePath, (string)$node->getNodeType()), 1389352984);
}
}
}
/**
* Generate a label for a node with a chaining mechanism. To be used in nodetype definitions.
*
* @param NodeInterface|null $node
* @return NodeLabelToken
*/
public function labelForNode(NodeInterface $node = null): NodeLabelToken
{
return new NodeLabelToken($node);
}
/**
* If this node type or any of the direct or indirect super types
* has the given name.
*
* @param NodeInterface $node
* @param string $nodeType
* @return bool
*/
public function isOfType(NodeInterface $node, string $nodeType): bool
{
return $node->getNodeType()->isOfType($nodeType);
}
/**
* @param string $methodName
* @return boolean
*/
public function allowsCallOfMethod($methodName)
{
return true;
}
}