Helper method to retrieve the closest document for a node

@param NodeInterface $node
@return NodeInterface
18803
public function getClosestDocument(NodeInterface $node)
    {
        if ($node->getNodeType()->isOfType('Neos.Neos:Document')) {
            return $node;
        }

        $flowQuery = new FlowQuery([$node]);

        return $flowQuery->closest('[instanceof Neos.Neos:Document]')->get(0);
    }
604517
private function getSiblingNode(NodeInterface $node, $previous = false)
    {
        $parentNode = $node->getParent();
        $children = $parentNode->getNodes();
        $previousNode = null;

        while ($child = current($children)) {
            if ($child->getPath() === $node->getPath()) {
                return $previous ? $previousNode : next($children);
            }

            $previousNode = $child;
            next($children);
        }

        throw new \RuntimeException(
            sprintf(
                'Could not find node with path "%s" as a child of "%s". This should not happen',
                $node->getPath(),
                $parentNode->getPath()
            )
        );
    }
679022
public function nodeToDslText(NodeInterface $node)
    {
        switch ($node->getNodeType()) {
            case Node::TYPE_USE_CASE:
                return $this->useCaseNodeToDslText($node);
                break;
            default:
                throw new \InvalidArgumentException('Unknown node type "' . $node->getNodeType() . '"');
                break;
        }
    }
173506
public function removeNode(NodeInterface $node): NodeInterface
    {
        unset($this->_nodes[$node->getId()]);

        if ($this->getParent()) {
            $this->getParent()->removeNode($node);
        }

        return $this;
    }
290111
protected function getDocBlock(AbstractNode $node): ?DocBlock
    {
        $comment = $node->getComment();

        if ($comment === null) {
            return null;
        }

        return $this->docBlockFactory->create($comment);
    }
836700
public function hydrateNodeFromNodeId(NodeInterface $node, $nodeId)
    {
        $siteId = $this->contextManager->getSiteId();
        $oldNode = $this->nodeRepository->findInLastVersion($nodeId, $node->getLanguage(), $siteId);
        if ($oldNode) {
            $node->setTemplate($oldNode->getTemplate());
            $this->duplicateArea($oldNode, $node);
        }

        return $node;
    }
719699
public function getLabel(\Neos\ContentRepository\Domain\Projection\Content\NodeInterface $node)
    {
        $label = Utility::evaluateEelExpression($this->getExpression(), $this->eelEvaluator, ['node' => $node], $this->defaultContextConfiguration);
        return $label;
    }
482832
public function searchAction(NodeInterface $node)
    {
        /* @var FusionView $view */
        $view = $this->view;
        $view->setFusionPath('ajaxSearch');
        $view->assign('value', $node);
    }
512427
protected function parseNode(NodeInterface $node)
    {
        return (object)[
            'type'       => $this->parseNodeType($node),
            'id'         => $node->getId() ?: null,
            'properties' => $this->parseNodeProperties($node),
        ];
    }
1288839
public static function dump(NodeInterface $node)
	{
		$prefix = str_repeat(static::DUMP_PREFIX, $node->getLevel());
		$left = $node->getLeftValue();
		$right = $node->getRightValue();
		$level = $node->getLevel();
		$title = $node->getNodeTitle();
		$dumpData = array(
			static::DUMP_PREFIX_POS => $prefix,
			static::DUMP_LEFT_POS => $left,
			static::DUMP_RIGHT_POS => $right,
			static::DUMP_LEVEL_POS => $level,
			static::DUMP_TITLE_POS => $title
		);
		ksort($dumpData);
		$dumpString = vsprintf(static::DUMP_FORMAT, $dumpData);
		
		return $dumpString;
	}
661890
public function getNodeCampaignMenu(NodeInterface $node) {
    if (!($campaign = $this->getNodeCampaignNode($node))) {
      return [];
    }

    return $this->getCampaignNodeCampaignMenu($campaign);
  }
928832
public function getStructureTypeForNode(NodeInterface $node)
    {
        $mixinTypes = $node->getPropertyValueWithDefault('jcr:mixinTypes', []);

        if (in_array('sulu:' . Structure::TYPE_PAGE, $mixinTypes)) {
            return Structure::TYPE_PAGE;
        }

        if (in_array('sulu:' . Structure::TYPE_SNIPPET, $mixinTypes)) {
            return Structure::TYPE_SNIPPET;
        }

        return;
    }
831004
public function createChildNodes(NodeInterface $node)
    {
        $nodeType = $node->getNodeType();
        foreach ($nodeType->getAutoCreatedChildNodes() as $childNodeName => $childNodeType) {
            try {
                $node->createNode($childNodeName, $childNodeType);
            } catch (NodeExistsException $exception) {
                // If you have a node that has been marked as removed, but is needed again
                // the old node is recovered
                $childNodePath = NodePaths::addNodePathSegment($node->getPath(), $childNodeName);
                $contextProperties = $node->getContext()->getProperties();
                $contextProperties['removedContentShown'] = true;
                $context = $this->contextFactory->create($contextProperties);
                $childNode = $context->getNode($childNodePath);
                if ($childNode->isRemoved()) {
                    $childNode->setRemoved(false);
                }
            }
        }
    }
1171741
public function traverse(Twig_NodeInterface $node)
    {
        ksort($this->visitors);
        foreach ($this->visitors as $visitors) {
            foreach ($visitors as $visitor) {
                $node = $this->traverseForVisitor($visitor, $node);
            }
        }

        return $node;
    }
560965
public function getOtherNode(Node $node)
    {
        if ($node === $this->getStartNode()) {
            return $this->getEndNode();
        }

        return $this->getStartNode();
    }
201188
public function sort(TreeNodeInterface $node)
    {
        if (!$node->getTree()->hasChildren($node)) {
            return array();
        }

        $parentId = $node->getId();
        $sortMode = $node->getSortMode();
        $sortDir = $node->getSortDir();

        $queryBuilder = $this->connection->createQueryBuilder();
        $queryBuilder
            ->select('t.id')
            ->from('tree', 't')
            ->where($queryBuilder->expr()->eq('t.parent_id', $parentId));

        switch ($sortMode) {
            case TreeInterface::SORT_MODE_TITLE:
                $queryBuilder
                    ->addSelect('evmf.backend AS sorter')
                    ->leftJoin('t', 'element', 'e', 't.type_id = e.eid')
                    ->leftJoin('e', 'element_version', 'ev', 'e.eid = ev.eid AND e.latest_version = ev.version')
                    ->leftJoin('ev', 'element_version_mapped_field', 'evmf', 'ev.id = evmf.element_version_id AND evmf.language = '.$this->connection->quote($this->sortLanguage))
                    ->orderBy('evmf.backend', $sortDir);
                break;

            case TreeInterface::SORT_MODE_CREATEDATE:
                $queryBuilder
                    ->addSelect('t.modify_time AS sorter')
                    ->orderBy('t.modify_time', $sortDir);
                break;

            case TreeInterface::SORT_MODE_PUBLISHDATE:
                $queryBuilder
                    ->addSelect('to.publish_time AS sorter')
                    ->leftJoin('t', 'tree_online', 'to', 'eto.tree_id = et.id AND eto.language = '.$this->connection->quote($this->sortLanguage))
                    ->orderBy('to.publish_time', $sortDir);
                break;

            case TreeInterface::SORT_MODE_CUSTOMDATE:
                $queryBuilder
                    ->addSelect('evmf.date AS sorter')
                    ->leftJoin('t', 'element', 'e', 't.type_id = e.eid')
                    ->leftJoin('e', 'element_version', 'ev', 'e.eid = ev.eid AND e.latest_version = ev.version')
                    ->leftJoin('ev', 'element_version_mapped_field', 'evmf', 'ev.id = evmf.element_version_id AND evmf.language = '.$this->connection->quote($this->sortLanguage))
                    ->orderBy('evmf.date', $sortDir);
                break;

            default:
                $queryBuilder
                    ->addSelect('t.sort AS sorter')
                    ->orderBy('t.sort', 'ASC');
                break;
        }

        $result = $this->connection->fetchAll($queryBuilder->getSQL());
        $result = array_column($result, 'id');

        return $result;
    }
1188417
public function cutNode(NodeInterface $node)
    {
        $this->nodeContextPath = $node->getContextPath();
        $this->mode = self::MODE_MOVE;
    }