@param NodeInterface $node
@param NodeInterface $newNode
@param boolean       $duplicateBlock

@return NodeInterface
352739
protected function duplicateArea(NodeInterface $node, NodeInterface $newNode, $duplicateBlock = true)
    {
        foreach ($node->getAreas() as $areaId => $area) {
            $newArea = clone $area;
            $newNode->setArea($areaId, $newArea);
            if (true === $duplicateBlock) {
                foreach ($area->getBlocks() as $block) {
                    if (!$block->isTransverse()) {
                        $newBlock = clone $block;
                        $this->blockRepository->getDocumentManager()->persist($newBlock);
                        $this->eventDispatcher->dispatch(BlockEvents::POST_BLOCK_CREATE, new BlockEvent($newBlock));
                        $newArea->addBlock($newBlock);
                    } else {
                        $newArea->addBlock($block);
                    }
                }
            }
        }

        return $newNode;
    }
1258545
private function mergeSuperTableBlockTypes(array $oldBlockTypes, array $newFields): array
    {
        $updatedBlockTypes = [];
        $blockTypeId = $oldBlockTypes[0]->id;
        $updatedBlockTypes[$blockTypeId] = [];
        $updatedBlockTypes[$blockTypeId]['fields'] = $this->mergeFieldLayout($oldBlockTypes[0]->getFieldLayout(), $newFields);

        return $updatedBlockTypes;
    }
584197
protected function pushClosureNode(\Twig_Node $blocks, \Twig_Node_Expression $variables, $parentName, \Twig_Node_Block $previous = null)
    {
        if (null === $previous) {
            return;
        }

        $name = $previous->getAttribute('name');
        $reference = new SuperblockReference($name, $variables, [], $previous->getTemplateLine(), $previous->getNodeTag());
        $reference->setAttribute('is_closure', true);
        $reference->setAttribute('parent_name', $parentName);

        $this->parser->setBlock($name, $previous);
        $blocks->setNode(\count($blocks), $reference);
    }
1340275
protected function verifyInterface(ClassNode $node, InterfaceNode $interfaceNode): void
    {
        $bridgedInterfaceReflection = $this->getBridgedInterfaceReflection($node->getMethods());

        $notMatchingMethods = $this->findNotMatchingMethodsForBridgeInterface($interfaceNode, $bridgedInterfaceReflection);

        foreach ($notMatchingMethods as $notMatchingMethod) {
            $message = sprintf(
                'The bridge interface has incorrect method \'%s\' signature. That violates the rule "%s"',
                $notMatchingMethod->getName(),
                static::RULE
            );

            $this->addViolation($interfaceNode, [$message]);
        }
    }
1255258
public function resolveRelationsNode(NodeContract $node, NodeContract $new_node)
    {
        $this->resolvePreviousNode($node, $new_node);
        $this->resolveNextNode($node, $new_node);
        $this->resolveGroupParent($node, $new_node);
    }
318594
public function reorder(TreeNodeInterface $node, TreeNodeInterface $beforeNode)
    {
        if ($beforeNode->getParentNode()->getId() !== $node->getParentNode()->getId()) {
            throw new InvalidNodeMoveException('Node and targetNode need to have the same parent.');
        }

        if ($node->getParentNode()->getSortMode() !== 'free') {
            return;
        }

        $sort = $beforeNode->getSort() + 1;

        $event = new ReorderNodeEvent($node, $sort);
        if ($this->dispatcher->dispatch(TreeEvents::BEFORE_REORDER_NODE, $event)->isPropagationStopped()) {
            return;
        }

        $updatesNodes = [];

        $currentSort = $sort + 1;
        foreach ($this->getChildren($node->getParentNode()) as $childNode) {
            if ($childNode->getSort() <= $sort) {
                $childNode->setSort($currentSort++);
                $updatesNodes[] = $childNode;
            }
        }

        $node->setSort($sort);
        $updateNodes[] = $node;

        $this->updateNodes($updateNodes);

        $event = new NodeEvent($node);
        $this->dispatcher->dispatch(TreeEvents::REORDER_NODE, $event);

        return;
    }
234217
boolean addNode(Block b, DatanodeDescriptor node, int replication) {
    // insert into the map if not there yet
    BlockInfo info = checkBlockInfo(b, replication);
    // add block to the data-node list and the node to the block info
    return node.addBlock(info);
  }
833540
public function addNode(NodeInterface $node)
    {
        if ($this->checkChildNode($node)) {
            $this->nodes->add($node);

            $node->setPosition(count($this->getNodes()));
            $node->setParent($this);
        }

        return $this;
    }
747195
public function setParent(Zend_Server_Reflection_Node $node, $new = false)
    {
        $this->_parent = $node;

        if ($new) {
            $node->attachChild($this);
            return;
        }
    }
1179875
private function getFlushedBuffer(NodeList $replacementNodes): Element {
        $newEl = $this->document()->createElement('p');
        $newEl->append($replacementNodes);

        return $newEl;
    }
1180155
public function duplicate($blocks, $owner = null)
    {
        if ($blocks instanceof BlockInterface) {
            $blocks = array($blocks);
        }

        $iterator = new \RecursiveIteratorIterator(
            new RecursiveBlockIterator($blocks),
            \RecursiveIteratorIterator::SELF_FIRST
        );

        $originalIdMap = array();
        $originalParentMap = array();

        $clones = array();

        // iterate over all owned blocks and disconnect parents keeping ids
        /** @var Block $block */
        foreach ($iterator as $block) {
            $blockId = $block->getId();
            $parentId = false;

            if (in_array($block->getId(), $originalIdMap)) {
                continue;
            }

            $clone = clone $block;
            $clone->setId(null);
            $clone->setParent(null);
            $clone->setOwner($owner);

            // if it has a parent we need to keep the id as reference for later
            if ($block->getParent()) {
                $parentId = $block->getParent()->getId();
            }

            if ($clone instanceof BlockContainerInterface) {
                $clone->setChildren(null);
            }

            $this->em->persist($clone);
            $this->em->flush($clone); // the block gets a new id

            $originalIdMap[$clone->getId()] = $blockId;
            if ($parentId) {
                $originalParentMap[$clone->getId()] = $parentId;
            }

            $clones[] = $clone;
        }

        // iterate over all new blocks and reset their parents
        foreach ($clones as $clone) {
            if (isset($originalParentMap[$clone->getId()])) {
                foreach ($clones as $parent) {
                    if (isset($originalParentMap[$clone->getId()]) &&
                        $originalParentMap[$clone->getId()] === $originalIdMap[$parent->getId()]) {
                        $clone->setParent($parent);
                        $parent->addChild($clone);

                        $this->em->flush($clone);
                        $this->em->flush($parent);
                    }
                }
            }
        }

        return $clones;
    }
47794
public function addNode(NodeInterface $node): NodeInterface
    {
        $this->_nodes[$node->getId()] = $node;

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

        return $this;
    }
547506
protected function performMakeChildOf(Node $node, Node $newParent)
    {

        $parentIdName = $this->getParentIdName();
        $rootIdName = $this->getRootIdName();

        // The node is already a child of newParent
        if ( ($node->getParentId()== $newParent->getId()) && $node->exists ) {
            return $this;
        }

        // Copy foreign keys
        $node[$parentIdName] = $newParent->getId();
        $node[$rootIdName] = $newParent[$rootIdName];

        // Set in-memory relations
        $node->setParent($newParent);
        $newParent->addChild($node);

        return $this;

    }
719794
private function upgradeNode(NodeInterface $node)
    {
        foreach ($node->getProperties('i18n:-*') as $property) {
            $property->remove();
        }

        foreach ($node->getNodes() as $childNode) {
            $this->upgradeNode($childNode);
        }
    }
1259801
public function isGrantedToCreateNode(NodeInterface $referenceNode, NodeType $typeOfNewNode = null)
    {
        return $this->privilegeManager->isGranted(CreateNodePrivilege::class, new CreateNodePrivilegeSubject($referenceNode, $typeOfNewNode));
    }
915529
public static function getClosestAggregateNode(NodeInterface $node)
    {
        while ($node !== null && !$node->getNodeType()->isAggregate()) {
            $node = $node->getParent();
        }
        return $node;
    }
722137
public function setNode(NodeInterface $node)
    {
        $this->nodeIdentifier = $node->getIdentifier();
        $this->workspaceName = $node->getContext()->getWorkspaceName();
        $this->dimension = $node->getContext()->getDimensions();

        $context = $node->getContext();
        if ($context instanceof ContentContext && $context->getCurrentSite() !== null) {
            $siteIdentifier = $this->persistenceManager->getIdentifierByObject($context->getCurrentSite());
        } else {
            $siteIdentifier = null;
        }
        $this->data = Arrays::arrayMergeRecursiveOverrule($this->data, [
            'nodeContextPath' => $node->getContextPath(),
            'nodeLabel' => $node->getLabel(),
            'nodeType' => $node->getNodeType()->getName(),
            'site' => $siteIdentifier
        ]);

        $node = self::getClosestAggregateNode($node);

        if ($node !== null) {
            $this->documentNodeIdentifier = $node->getIdentifier();
            $this->data = Arrays::arrayMergeRecursiveOverrule($this->data, [
                'documentNodeContextPath' => $node->getContextPath(),
                'documentNodeLabel' => $node->getLabel(),
                'documentNodeType' => $node->getNodeType()->getName()
            ]);
        }
    }