findByParentAndNodeTypeInContext() public method

TODO Move to a new Node operation getDescendantNodes(...)
public findByParentAndNodeTypeInContext ( string $parentPath, string $nodeTypeFilter, Context $context, boolean $recursive = false ) : array<\Neos\ContentRepository\Domain\Model\NodeInterface>
$parentPath string Absolute path of the parent node
$nodeTypeFilter string Filter the node type of the nodes, allows complex expressions (e.g. "Neos.Neos:Page", "!Neos.Neos:Page,Neos.Neos:Text" or NULL)
$context Neos\ContentRepository\Domain\Service\Context The containing workspace
$recursive boolean If TRUE *all* matching nodes underneath the specified parent path are returned
return array<\Neos\ContentRepository\Domain\Model\NodeInterface>
示例#1
0
 /**
  * Returns all direct child nodes of this node.
  * If a node type is specified, only nodes of that type are returned.
  *
  * @param string $nodeTypeFilter If specified, only nodes with that node type are considered
  * @param integer $limit An optional limit for the number of nodes to find. Added or removed nodes can still change the number nodes!
  * @param integer $offset An optional offset for the query
  * @return array<\Neos\ContentRepository\Domain\Model\NodeInterface> An array of nodes or an empty array if no child nodes matched
  * @api
  */
 public function getChildNodes($nodeTypeFilter = null, $limit = null, $offset = null)
 {
     $nodes = $this->context->getFirstLevelNodeCache()->getChildNodesByPathAndNodeTypeFilter($this->getPath(), $nodeTypeFilter);
     if ($nodes === false) {
         $nodes = $this->nodeDataRepository->findByParentAndNodeTypeInContext($this->getPath(), $nodeTypeFilter, $this->context, false);
         $this->context->getFirstLevelNodeCache()->setChildNodesByPathAndNodeTypeFilter($this->getPath(), $nodeTypeFilter, $nodes);
     }
     if ($offset !== null || $limit !== null) {
         $offset = $offset === null ? 0 : $offset;
         return array_slice($nodes, $offset, $limit);
     }
     return $nodes;
 }
 /**
  * {@inheritdoc}
  *
  * @param FlowQuery $flowQuery the FlowQuery object
  * @param array $arguments the arguments for this operation
  * @return void
  */
 public function evaluate(FlowQuery $flowQuery, array $arguments)
 {
     $context = $flowQuery->getContext();
     if (!isset($context[0]) || empty($arguments[0])) {
         return;
     }
     $result = array();
     $selectorAndFilter = $arguments[0];
     $parsedFilter = null;
     $parsedFilter = FizzleParser::parseFilterGroup($selectorAndFilter);
     if (isset($parsedFilter['Filters']) && $this->hasOnlyInstanceOfFilters($parsedFilter['Filters'])) {
         $nodeTypes = array();
         foreach ($parsedFilter['Filters'] as $filter) {
             $nodeTypes[] = $filter['AttributeFilters'][0]['Operand'];
         }
         /** @var NodeInterface $contextNode */
         foreach ($context as $contextNode) {
             $result = array_merge($result, $this->nodeDataRepository->findByParentAndNodeTypeInContext($contextNode->getPath(), implode(',', $nodeTypes), $contextNode->getContext(), true));
         }
     } else {
         foreach ($parsedFilter['Filters'] as $filter) {
             $filterResults = array();
             $generatedNodes = false;
             if (isset($filter['IdentifierFilter'])) {
                 if (!preg_match(UuidValidator::PATTERN_MATCH_UUID, $filter['IdentifierFilter'])) {
                     throw new FlowQueryException('find() requires a valid identifier', 1332492263);
                 }
                 /** @var NodeInterface $contextNode */
                 foreach ($context as $contextNode) {
                     $filterResults = array($contextNode->getContext()->getNodeByIdentifier($filter['IdentifierFilter']));
                 }
                 $generatedNodes = true;
             } elseif (isset($filter['PropertyNameFilter']) || isset($filter['PathFilter'])) {
                 $nodePath = isset($filter['PropertyNameFilter']) ? $filter['PropertyNameFilter'] : $filter['PathFilter'];
                 foreach ($context as $contextNode) {
                     $node = $contextNode->getNode($nodePath);
                     if ($node !== null) {
                         array_push($filterResults, $node);
                     }
                 }
                 $generatedNodes = true;
             }
             if (isset($filter['AttributeFilters']) && $filter['AttributeFilters'][0]['Operator'] === 'instanceof') {
                 foreach ($context as $contextNode) {
                     $filterResults = array_merge($filterResults, $this->nodeDataRepository->findByParentAndNodeTypeInContext($contextNode->getPath(), $filter['AttributeFilters'][0]['Operand'], $contextNode->getContext(), true));
                 }
                 unset($filter['AttributeFilters'][0]);
                 $generatedNodes = true;
             }
             if (isset($filter['AttributeFilters']) && count($filter['AttributeFilters']) > 0) {
                 if (!$generatedNodes) {
                     throw new FlowQueryException('find() needs an identifier, path or instanceof filter for the first filter part', 1436884196);
                 }
                 $filterQuery = new FlowQuery($filterResults);
                 foreach ($filter['AttributeFilters'] as $attributeFilter) {
                     $filterQuery->pushOperation('filter', array($attributeFilter['text']));
                 }
                 $filterResults = $filterQuery->get();
             }
             $result = array_merge($result, $filterResults);
         }
     }
     $flowQuery->setContext(array_unique($result));
 }