Neos\Neos\Eel\FlowQueryOperations\ParentsOperation::evaluate PHP Méthode

evaluate() public méthode

public evaluate ( FlowQuery $flowQuery, array $arguments ) : void
$flowQuery Neos\Eel\FlowQuery\FlowQuery the FlowQuery object
$arguments array the arguments for this operation
Résultat void
    public function evaluate(FlowQuery $flowQuery, array $arguments)
    {
        $output = array();
        $outputNodePaths = array();
        foreach ($flowQuery->getContext() as $contextNode) {
            /** @var NodeInterface $contextNode */
            $siteNode = $contextNode->getContext()->getCurrentSiteNode();
            while ($contextNode !== $siteNode && $contextNode->getParent() !== null) {
                $contextNode = $contextNode->getParent();
                if (!isset($outputNodePaths[$contextNode->getPath()])) {
                    $output[] = $contextNode;
                    $outputNodePaths[$contextNode->getPath()] = true;
                }
            }
        }
        $flowQuery->setContext($output);
        if (isset($arguments[0]) && !empty($arguments[0])) {
            $flowQuery->pushOperation('filter', $arguments);
        }
    }

Usage Example

 /**
  * @test
  */
 public function parentsWillReturnTheSiteNodeAsRootLevelParent()
 {
     $siteNode = $this->createMock(NodeInterface::class);
     $firstLevelNode = $this->createMock(NodeInterface::class);
     $secondLevelNode = $this->createMock(NodeInterface::class);
     $siteNode->expects($this->any())->method('getPath')->will($this->returnValue('/site'));
     $mockContext = $this->getMockBuilder(\Neos\Neos\Domain\Service\ContentContext::class)->disableOriginalConstructor()->getMock();
     $mockContext->expects($this->any())->method('getCurrentSiteNode')->will($this->returnValue($siteNode));
     $firstLevelNode->expects($this->any())->method('getParent')->will($this->returnValue($siteNode));
     $firstLevelNode->expects($this->any())->method('getPath')->will($this->returnValue('/site/first'));
     $secondLevelNode->expects($this->any())->method('getContext')->will($this->returnValue($mockContext));
     $secondLevelNode->expects($this->any())->method('getParent')->will($this->returnValue($firstLevelNode));
     $secondLevelNode->expects($this->any())->method('getPath')->will($this->returnValue('/site/first/second'));
     $context = array($secondLevelNode);
     $q = new FlowQuery($context);
     $operation = new ParentsOperation();
     $operation->evaluate($q, array());
     $output = $q->getContext();
     $this->assertEquals(array($siteNode, $firstLevelNode), $output);
 }
ParentsOperation