Access node's references from Plugin


I’m sorry to disturb you with a really simple question, but I’ve now been trying for almost 3 hours: I’ve created a Neos Command Controller that added a huge amount of nodes to the Repository. I’ve defined multiple node-types and some are referencing each other. I’m able to open the GUI and look and change the references - works perfectly.

Now I’ve created a small plugin that needs to get the node’s references. In the Plugin Controller I call $this->request->getInternalArgument(’__node’) and I’m able to access the properties of the Node via getProperty() (e.g. there is a string called “name” and and integer called “pos”). Those properties have been added by the Command Controller via $node->setProperty($key, $value). In the same way the references have been added. However, I’m only able get integers and strings with getProperty(), but not the references. getproperties() returns an array with all Properties except the references. Does someone have an idea to help me out here?


Is it maype possible to get all referenced nodes via FlowQuery?

H! I did a small test and it works with FlowQuery:


    'Neos.Neos:Content': true
       type: reference

Flow Query

$context = $this->contextFactory->create(array('workspaceName' => 'live', 'currentDateTime' => new \Neos\Flow\Utility\Now(), 'dimensions' => array(), 'invisibleContentShown' => FALSE, 'removedContentShown' => FALSE, 'inaccessibleContentShown' => FALSE));
$site = $context->getRootNode();

$node = (new \Neos\Eel\FlowQuery\FlowQuery([$site]))
    ->find('[instanceof Foo.Bar:Test]')
    ->context(array('workspaceName' => 'live'))



Flow Variable Dump
 string "referenceNode" (13) => Neos\ContentRepository\Domain\Model\Node prototype object proxy
   nodeData => Neos\ContentRepository\Domain\Model\NodeData prototype persistable proxy
    Persistence_Object_Identifier => string "4f7e91bc-b703-4c0d-a55f-35759f17141f" (36)
1 Like

Great - works if I get it by Flow Query. Thank you!

Do you have an idea if it is possible to filter by referenceS and not only by reference?

$query = (new \Neos\Eel\FlowQuery\FlowQuery([$site]))
                    ->find('[instanceof Example:Document.Type]')
                    ->filter('[References *= "' . $references. '"]')
                    ->filter('[Reference *= "' . $reference . '"]');

Filter by reference works, but filter by referenceS (array) returns an empty result.

I don’t understand the question. A nodeType with type reference is always an array because you can add one or more references (nodes). I didn’t test it but if you want to to search more than one reference you can do something like .filter('[reference *= "$referenceOne"], [reference *= "$referenceTwo"]') , AFAIK.

EDIT:// Sorry thats worng. I looked into the docs and saw that these are two different editors. I will test it :slight_smile:

Okay, I thought there are two options:

  1. reference => ONE reference to another node
  2. references => ARRAY of refrerences to multiple nodes

My node does have a reference property AND a references property. I can filter the reference property to search for a certain node, but not the references.

Do I have a general error?

Hm… I’m confused. Looks like a bug to me.

My NodeType (I removed the irrelevant stuff):

      type: reference
            nodeTypes: ['Neos.Neos:Document']
      type: references
            nodeTypes: ['Neos.Neos:Document']

Created this node in the backend with the following nodes:

properties => array(2)
    string "referenceNode" (13) => string "a2599b51-557e-4b5e-89b6-0776c17ca500" (36)
    string "referenceNodes" (14) => array(3)
      integer 0 => string "c5d18c75-e431-4d50-a189-d707aa90d238" (36)
      integer 1 => string "4991ef71-9ec0-4908-94a2-318b29e2c67d" (36)
      integer 2 => string "490e2a1b-b145-403e-865e-4638b2b65b31" (36)

Did 2 tests with the following FlowQuerys.

Working (referenceNode):

$reference = (new \Neos\Eel\FlowQuery\FlowQuery([$site]))->find('#a2599b51-557e-4b5e-89b6-0776c17ca500')->context(array('workspaceName' => 'live'))->get(0);
$node = (new \Neos\Eel\FlowQuery\FlowQuery([$site]))
            ->find('[instanceof Foo.Bar:Test]')
            ->filter('[referenceNode *= "' .$reference. '"]')
            ->context(array('workspaceName' => 'live'))

Not working (referenceNodes):

$reference = (new \Neos\Eel\FlowQuery\FlowQuery([$site]))->find('#4991ef71-9ec0-4908-94a2-318b29e2c67d')->context(array('workspaceName' => 'live'))->get(0);
$node = (new \Neos\Eel\FlowQuery\FlowQuery([$site]))
            ->find('[instanceof Foo.Bar:Test]')
            ->filter('[referenceNodes *= "' .$reference. '"]')
            ->context(array('workspaceName' => 'live'))

This leads to the “Warning”:

Warning: strpos() expects parameter 1 to be string, array given in /usr/www/users/geopard/dev/test/neos/Data/Temporary/Development/Cache/Code/Flow_Object_Classes/Neos_Eel_FlowQuery_Operations_Object_FilterOperation.php line 242

Do you see this warning, too? Or maybe I did something wrong here… not sure.


Show Exception Log
Exception #1: Warning: strpos() expects parameter 1 to be string, array given in /usr/www/users/geopard/dev/test/neos/Data/Temporary/Development/Cache/Code/Flow_Object_Classes/Neos_Eel_FlowQuery_Operations_Object_FilterOperation.php line 242

31 Neos\Flow\Error\ErrorHandler::handleError(2, "strpos() expects parameter 1 to be string, array given", "/usr/www/users/geopard/dev/test/neos/Data/Tempor…el_FlowQuery_Operations_Object_FilterOperation.php", 242, array|3|)
30 strpos(array|3|, "Node /sites/test/node-qpm2pqkyb5hai/node-16g63b0…language=de_DE[Foo.Bar:ReferenceNode]")
29 Neos\Eel\FlowQuery\Operations\Object\FilterOperation_Original::evaluateOperator(array|3|, "*=", "Node /sites/test/node-qpm2pqkyb5hai/node-16g63b0…language=de_DE[Foo.Bar:ReferenceNode]")
28 Neos\ContentRepository\Eel\FlowQueryOperations\FilterOperation_Original::evaluateOperator(array|3|, "*=", "Node /sites/test/node-qpm2pqkyb5hai/node-16g63b0…language=de_DE[Foo.Bar:ReferenceNode]")
27 Neos\Eel\FlowQuery\Operations\Object\FilterOperation_Original::matchesAttributeFilter(Neos\ContentRepository\Domain\Model\Node, array|7|)
26 Neos\Eel\FlowQuery\Operations\Object\FilterOperation_Original::matchesFilter(Neos\ContentRepository\Domain\Model\Node, array|4|)
25 Neos\Eel\FlowQuery\Operations\Object\FilterOperation_Original::matchesFilterGroup(Neos\ContentRepository\Domain\Model\Node, array|4|)
24 Neos\Eel\FlowQuery\Operations\Object\FilterOperation_Original::evaluate(Neos\Eel\FlowQuery\FlowQuery, array|1|)
23 Neos\ContentRepository\Eel\FlowQueryOperations\FilterOperation_Original::evaluate(Neos\Eel\FlowQuery\FlowQuery, array|1|)
22 Neos\Eel\FlowQuery\FlowQuery_Original::evaluateOperations()
21 Neos\Eel\FlowQuery\FlowQuery_Original::__call("get", array|1|)
20 Foo\Bar\Command\TestCommandController_Original::testCommand()
19 call_user_func_array(array|2|, array|0|)
18 Neos\Flow\Cli\CommandController_Original::callCommandMethod()
17 Neos\Flow\Cli\CommandController_Original::processRequest(Neos\Flow\Cli\Request, Neos\Flow\Cli\Response)
16 Neos\Flow\Mvc\Dispatcher_Original::initiateDispatchLoop(Neos\Flow\Cli\Request, Neos\Flow\Cli\Response)
15 Neos\Flow\Mvc\Dispatcher_Original::dispatch(Neos\Flow\Cli\Request, Neos\Flow\Cli\Response)
14 Neos\Flow\Cli\CommandRequestHandler::Neos\Flow\Cli\{closure}()
13 Closure::__invoke()
12 Neos\Flow\Security\Context_Original::withoutAuthorizationChecks(Closure)
11 Neos\Flow\Security\Context::withoutAuthorizationChecks(Closure)
10 call_user_func_array(array|2|, array|1|)
9 Neos\Flow\Security\Context::Flow_Aop_Proxy_invokeJoinPoint(Neos\Flow\Aop\JoinPoint)
8 Neos\Flow\Aop\Advice\AdviceChain::proceed(Neos\Flow\Aop\JoinPoint)
7 Neos\Flow\Session\Aspect\LazyLoadingAspect_Original::callMethodOnOriginalSessionObject(Neos\Flow\Aop\JoinPoint)
6 Neos\Flow\Aop\Advice\AroundAdvice::invoke(Neos\Flow\Aop\JoinPoint)
5 Neos\Flow\Aop\Advice\AdviceChain::proceed(Neos\Flow\Aop\JoinPoint)
4 Neos\Flow\Security\Context::withoutAuthorizationChecks(Closure)
3 Neos\Flow\Cli\CommandRequestHandler::handleRequest()
2 Neos\Flow\Core\Bootstrap::run()
1 require("/usr/www/users/geopard/dev/test/neos/Packages/Framework/Neos.Flow/Scripts/flow.php")

No, I don’t get any warnings - just an empty result.

However, I’m unable to find a mistake at your code, too.

1 Like

I will open an issue on github later because it can’t be right that FilterOperation.php in Neos/Eel throws an exception like that.

Ok this is a known issue:

Okay, thank you very much.

I’s opened in 2014 - I think I’ll need to search a workaround :smiley:

Just to get sure, can you check if you’re at least on Flow 5.2 and does not fix this? As far as I understand the issue, this feature should be the solution, no?

My Installation was on Flow 4.2.14
I didn’t test it with 5.2 (will try it later)

I’ve changed my node structure to avoid this issue. Thank you for your help.