Add page content to the index document

@param NodeTranslation  $nodeTranslation
@param HasNodeInterface $page
@param array            $doc
176388
protected function addPageContent(NodeTranslation $nodeTranslation, $page, &$doc)
    {
        $this->enterRequestScope($nodeTranslation->getLang());
        if ($this->logger) {
            $this->logger->debug(
                sprintf(
                    'Indexing page "%s" / lang : %s / type : %s / id : %d / node id : %d',
                    $page->getTitle(),
                    $nodeTranslation->getLang(),
                    get_class($page),
                    $page->getId(),
                    $nodeTranslation->getNode()->getId()
                )
            );
        }

        $renderer = $this->container->get('templating');
        $doc['content'] = '';

        if ($page instanceof SearchViewTemplateInterface) {
            $doc['content'] = $this->renderCustomSearchView($nodeTranslation, $page, $renderer);

            return null;
        }

        if ($page instanceof HasPagePartsInterface) {
            $doc['content'] = $this->renderDefaultSearchView($nodeTranslation, $page, $renderer);

            return null;
        }
    }
51552
private function mapParent($document, NodeInterface $node, $options = [])
    {
        // TODO: performance warning: We are eagerly fetching the parent node
        $targetNode = $node->getParent();

        // Do not map non-referenceable parent nodes
        if (!$targetNode->hasProperty('jcr:uuid')) {
            return;
        }

        $document->setParent($this->proxyFactory->createProxyForNode($document, $targetNode, $options));
    }
917020
private function updateChildrenPageTranslationPath(
        PageInterface $page,
        UnitOfWork $uow,
        ClassMetadata $metadata,
        $from,
        $to,
        $locale
    ) {
        // TODO use url generator or i18n routing prefix strategy
        $localePrefix = $locale != 'fr' ? '/' . $locale : '';
        foreach ($page->getChildren() as $child) {
            $translation = $child->translate($locale);
            $oldPath = $translation->getPath();
            if (0 === strpos($oldPath, $from)) {
                $newPath = str_replace($from, $to, $oldPath);
                $translation->setPath($newPath);
                $uow->recomputeSingleEntityChangeSet($metadata, $translation);

                if (0 < strlen($oldPath) && 0 < strlen($newPath) && $oldPath != $newPath) {
                    $this->redirections[] = array(
                        'from' => $localePrefix . $oldPath,
                        'to'   => $localePrefix . $newPath,
                    );
                }

                // Update the children pages translations paths.
                if ($child->hasChildren()) {
                    $this->updateChildrenPageTranslationPath($child, $uow, $metadata, $oldPath, $newPath, $locale);
                }
            }
        }
    }
1066188
public function addTranslationData($entity, $propertyPath, $data)
    {
        $metadata = $this->metadataCollection->getMetadata($entity);
        $property = $metadata->getProperty($propertyPath);
        $strategy = $this->strategyResolver->getStrategy($property->getStrategy());
        $strategy->addTranslationData($entity, $property, $data, $metadata);
    }
1310632
public function addNodeTranslation(NodeTranslation $nodeTranslation)
    {
        $this->nodeTranslations[] = $nodeTranslation;
        $nodeTranslation->setNode($this);

        return $this;
    }
150739
public function removeTranslation(PageInterface $page)
    {
        $this->translations->removeElement($page);
        $page->getOriginals()->removeElement($this);

        return $this;
    }
1265593
public function removeAllTranslations($document, NodeInterface $node, ClassMetadata $metadata)
    {
        foreach ($metadata->translatableFields as $field) {
            $mapping = $metadata->mappings[$field];
            $node->setProperty($mapping['property'], null);
        }
    }
630873
public function hasParentNodeTranslationsForLanguage(
        NodeTranslation $nodeTranslation,
        $language
    ) {
        $parentNode = $nodeTranslation->getNode()->getParent();
        if ($parentNode !== null) {
            $parentNodeTranslation = $parentNode->getNodeTranslation(
                $language,
                true
            );
            if ($parentNodeTranslation !== null) {
                return $this->hasParentNodeTranslationsForLanguage(
                    $parentNodeTranslation,
                    $language
                );
            } else {
                return false;
            }
        }

        return true;
    }
361700
public function indexNodeTranslation(NodeTranslation $nodeTranslation, $add = false)
    {
        // Retrieve the public NodeVersion
        $publicNodeVersion = $nodeTranslation->getPublicNodeVersion();
        if (is_null($publicNodeVersion)) {
            return false;
        }

        $refPage = $this->getNodeRefPage($publicNodeVersion);
        if ($refPage->isStructureNode()) {
            return true;
        }

        // Only index online NodeTranslations
        if (!$nodeTranslation->isOnline()) {
            return false;
        }

        $node = $nodeTranslation->getNode();
        if ($this->isIndexable($refPage)) {
            // Retrieve the referenced entity from the public NodeVersion
            $page = $publicNodeVersion->getRef($this->em);

            $this->addPageToIndex($nodeTranslation, $node, $publicNodeVersion, $page);
            if ($add) {
                $this->searchProvider->addDocuments($this->documents);
                $this->documents = [];
            }
        }

        return true; // return true even if the page itself should not be indexed. This makes sure its children are being processed (i.e. structured nodes)
    }
606514
public function setNodeTranslation(\Kunstmaan\NodeBundle\Entity\NodeTranslation $nodeTranslation = null)
    {
        $this->nodeTranslation = $nodeTranslation;

        return $this;
    }
133417
public function getDocument($document, $rootNode)
	{
		if ($rootNode == null)
		{
			$rootNode = "page";
		}
		return $this->_persistUtil->getDocument($document, $rootNode);
	}
1291077
public function updateNodeTranslation(NodeInterface &$node, array $product, string $langcode) {
    $description = (isset($product['attributes']['description'])) ? $product['attributes']['description'] : '';

    $categories = (isset($product['categories'])) ? $product['categories'] : [];

    $config = $this->configFactory->get('acm.connector');
    $sku_field_name = $config->get('sku_field_name') ?: 'field_skus';
    $category_field_name = $config->get('category_field_name');
    $text_format = $config->get('text_format') ?: 'rich_text';

    $node_title = html_entity_decode($product['name']);
    if ($config->get('product_title_use_sku')) {
      $node_title = html_entity_decode($product['sku']);
    }
    $node->setTitle($node_title);
    $body = [
      'value' => $description,
      'format' => $text_format,
    ];
    $node->set('body', $body);

    // Add categories if they're configured to be synced.
    if ($category_field_name) {
      $categories = $this->formatCategories($categories);
      $node->{$category_field_name} = $categories;
    }
    $node->{$sku_field_name} = [$product['sku']];

    if ($config->get('product_publish')) {
      $node->setPublished();
    }
    else {
      $node->setUnpublished();
    }

    // Invoke the alter hook to allow all modules to update the node.
    $this->moduleHandler->alter('acm_sku_product_node_translation_update', $node, $product, $langcode);
  }
501338
public function makeTranslationCopy(PageInterface $page, $locale)
    {
        $pageClass = $this->pageManager->getClassName();
        /** @var PageInterface $pageCopy */
        $pageCopy = new $pageClass();

        $pageCopy->setPageName($page->getPageName());
        $pageCopy->setMetaTitle($page->getMetaTitle());
        $pageCopy->setUrl($page->getUrl());
        $pageCopy->setMetaKeyword($page->getMetaKeyword());
        $pageCopy->setMetaDescription($page->getMetaDescription());
        $pageCopy->setActiveFrom($page->getActiveFrom());
        $pageCopy->setIsHome($page->getIsHome());
        $pageCopy->setLocale($locale);
        $pageCopy->setTemplateName($page->getTemplateName());
        $pageCopy->setOriginal($page);

        $layoutBlocks = $page->getLayoutBlock();
	    $om = $this->registry->getManager();

        foreach ($layoutBlocks as $layoutBlock) {

            /** @var $newLayoutBlock \Networking\InitCmsBundle\Model\LayoutBlockInterface */
            $newLayoutBlock = clone $layoutBlock;


            $content = $om->getRepository($newLayoutBlock->getClassType())->find(
                $newLayoutBlock->getObjectId()
            );
            $newContent = clone $content;

            $om->persist($newContent);
            $om->flush();

            $newLayoutBlock->setObjectId($newContent->getId());
            $newLayoutBlock->setPage($pageCopy);

            $om->persist($newLayoutBlock);
        }

	    $om->persist($pageCopy);

        $om->flush();

        return $pageCopy;
    }
387243
public function getNodeTranslationFor(HasNodeInterface $page)
    {
        $version = $this->getNodeVersionFor($page);

        return $version ? $version->getNodeTranslation() : null;
    }
609368
public function setBlamesOnNode(
        LocalizedBlameBehavior $document,
        NodeInterface $node,
        $locale,
        DocumentAccessor $accessor,
        $userId
    ) {
        if (!$document instanceof BlameBehavior && !$locale) {
            return;
        }

        $encoding = $this->getPropertyEncoding($document);

        $creatorPropertyName = $this->propertyEncoder->encode($encoding, static::CREATOR, $locale);
        if (!$node->hasProperty($creatorPropertyName)) {
            $accessor->set(self::CREATOR, $userId);
            $node->setProperty(
                $creatorPropertyName,
                $document->getCreator()
            );
        }

        $accessor->set(self::CHANGER, $userId);
        $node->setProperty(
            $this->propertyEncoder->encode($encoding, static::CHANGER, $locale),
            $userId
        );
    }
386332
private function validateDocumentRegistration($document, $locale, NodeInterface $node, $oid, $uuid)
    {
        if (null === $uuid) {
            throw new DocumentManagerException(sprintf(
                'Node "%s" of type "%s" has no UUID. Only referencable nodes can be registered by the document manager',
                $node->getPath(), $node->getPrimaryNodeType()->getName()
            ));
        }

        $documentNodeKey = $this->getNodeLocaleKey($node->getIdentifier(), $locale);
        if (array_key_exists($uuid, $this->nodeMap) && array_key_exists($documentNodeKey, $this->nodeDocumentMap)) {
            $registeredDocument = $this->nodeDocumentMap[$documentNodeKey];

            throw new \RuntimeException(sprintf(
                'Document "%s" (%s) is already registered for node "%s" (%s) when trying to register document "%s" (%s)',
                spl_object_hash($registeredDocument),
                get_class($registeredDocument),
                $uuid,
                $node->getPath(),
                $oid,
                get_class($document)
            ));
        }
    }
788122
public function duplicatePage(Node $node, $locale, $title = 'New page')
    {
        $user = $this->getAdminUser();

        $sourceNodeTranslations = $node->getNodeTranslation($locale, true);
        $sourcePage = $sourceNodeTranslations->getPublicNodeVersion()->getRef($this->em);
        $targetPage = $this->cloneHelper->deepCloneAndSave($sourcePage);
        $targetPage->setTitle($title);

        if ($node->getParent()) {
            $parentNodeTranslation = $node->getParent()->getNodeTranslation($locale, true);
            $parent = $parentNodeTranslation->getPublicNodeVersion()->getRef($this->em);
            $targetPage->setParent($parent);
        }
        $this->em->persist($targetPage);
        $this->em->flush();

        /* @var Node $nodeNewPage */
        $nodeNewPage = $this->em->getRepository(Node::class)->createNodeFor($targetPage, $locale, $user);

        $nodeTranslation = $nodeNewPage->getNodeTranslation($locale, true);
        if ($targetPage->isStructureNode()) {
            $nodeTranslation->setSlug('');
            $this->em->persist($nodeTranslation);
        }
        $this->em->flush();

        return $nodeTranslation;
    }