-
-
Notifications
You must be signed in to change notification settings - Fork 219
/
NodeIdentityConverterAspect.php
46 lines (42 loc) · 1.52 KB
/
NodeIdentityConverterAspect.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
<?php
namespace Neos\Neos\Routing;
/*
* 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\Flow\Aop\JoinPointInterface;
use Neos\ContentRepository\Domain\Model\NodeInterface;
/**
* Aspect to convert a node object to its context node path. This is used in URI
* building in order to make linking to nodes a lot easier.
*
* On the long term, type converters should be able to convert the reverse direction
* as well, and then this aspect could be removed.
*
* @Flow\Scope("singleton")
* @Flow\Aspect
*/
class NodeIdentityConverterAspect
{
/**
* Convert the object to its context path, if we deal with ContentRepository nodes.
*
* @Flow\Around("method(Neos\Flow\Persistence\AbstractPersistenceManager->convertObjectToIdentityArray())")
* @param JoinPointInterface $joinPoint the joinpoint
* @return string|array the context path to be used for routing
*/
public function convertNodeToContextPathForRouting(JoinPointInterface $joinPoint): array
{
$objectArgument = $joinPoint->getMethodArgument('object');
if ($objectArgument instanceof NodeInterface) {
return ['__contextNodePath' => $objectArgument->getContextPath()];
}
return $joinPoint->getAdviceChain()->proceed($joinPoint);
}
}