Neos Class Query

Hey guys,

I have a new Class in my Neos Instance.

In my ActionController I use the Index Action but the result is 0.
In PhpMyAdmin I get 12 results with the same query.

Can you help me?

$filterArr = array(‘nodetype’ => ‘TYPO3.Neos.NodeTypes:Page’, ‘parentpath’ => ‘/sites/website/node-56a5b4a7a127c’);
//$filterArr = array(‘nodetype’ => ‘TYPO3.Neos.NodeTypes:Page’);
$classname = ‘\TYPO3\TYPO3CR\Domain\Model\NodeData’;
$query = $this->persistenceManager->createQueryForType($classname);
foreach ($filterArr as $property => $filter) {
if (isset($filter)) {
$constraintArr[] = $query->equals($property, $filter);
}
}
$results = $query->matching($query->logicalAnd($constraintArr))->execute();

$countresult = count($results);
$this->view->assign(‘countresult’, $countresult);

Did you try to use TYPO3\Eel\FlowQuery\FlowQuery() instead of raw queries in your controller?

NEVER use this low level stuff to access your nodes.

The official API is to use FlowQuery, like this:

$context = $this->contextFactory->create(array('workspaceName' => $workspaceName, 'dimensions' => $dimensions));
$node = $context->getNodeByIdentifier('0036abe7-1f50-43a9-a835-5ecc24332075'); // Use the identifier of the node at path /sites/website/node-56a5b4a7a127c, prefere UUID because they never change

$query = new FlowQuery(array($node));
$query = $query->children('[instanceof TYPO3.Neos.NodeTypes:Page]');
$nodes = $query->get() // Should return an array of Nodes

Hope that help,

1 Like

I cant find a documentation about FlowQuery.
How can I list all sites whose parentpath = /sites/website/node-56a5b4a7a127c

I have tried this, but I get Error 500

$context = $this->contextFactory->create(array('parentpath' => '/sites/website/node-56a5b4a7a127c'));
$query = new FlowQuery(array($context));
$query = $query->filter('[instanceof TYPO3.Neos.NodeTypes:Page]');
$nodes = $query->get();
1 Like

You need to create a context with the correct workspace and dimensions. From the context you can get the node by identifier (don’t use the path because the path can change). You can get the node identifier from the inspector.

Once you have the node with the correct identifier, you can use the FlowQuery to select the node that you needs. I edit the FlowQuery bellow to get all the children Page

You can try to create a context like this:

$context = $this->contextFactory->create([
    'workspaceName' => 'live'
])

Ok I have changed the line and add the workspaceName but I get Error 500

$context = $this->contextFactory->create(['workspaceName' => 'live']);
$node = $context->getNodeByIdentifier('9ca27b98-8406-41b5-8dd6-84feb58f690f');
$query = new FlowQuery(array($node));
$query = $query->children('[instanceof TYPO3.Neos.NodeTypes:Page]');
$nodes = $query->get();

What Error 500?
Could you check your Logs (Data/Logs/Exception/)?

This works for me, thank you for your help

$workspaceName = "live";
$context = $this->contextFactory->create(array('workspaceName' => $workspaceName));
$node = $context->getNodeByIdentifier('9ca27b98-8406-41b5-8dd6-84feb58f690f');
$articles = (new FlowQuery(array($node)))->children('[instanceof TYPO3.Neos.NodeTypes:Page]')->context(array('workspaceName' => 'live'))->get();
$this->view->assign('articles', $articles);
$articles = (new FlowQuery(array($node)))->children('[instanceof TYPO3.Neos.NodeTypes:Page]')->context(array('workspaceName' => 'live'))->get();

Can be simplified to:

$articles = (new FlowQuery(array($node)))->children('[instanceof TYPO3.Neos.NodeTypes:Page]')->get();

Because you are already in live workspace, no need to change the context there.

Thank you!

how can I fetch the image with getproperty() function, I am getting this
Flow Variable Dump

Neos\Flow\Persistence\Doctrine\Proxies_CG_\Neos\Media\Domain\Model\Image persistable proxy

Don’t write in a three year old thread, but create your own topic with a saying title. That will also help others in the future, searching for a solution to the exact usecase.