create a copy of a given page object in a given locale.

@param PageInterface $page
@param $locale

@return PageInterface
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;
    }
744768
public function getParentPagesChoices($locale, $id = null)
    {
        $qb = $this->getParentPagesQuery($locale, $id);

        return $qb->getQuery()->execute();
    }
670402
protected function createPage($name, $hierarchy, Page $parent = null): Page
    {
        $page = new Page();
        $page->setParent($parent);
        $page->setHierarchy($hierarchy);
        $page->setPublish(1);
        $page->setRedirectType(0);
        $page->setSection('');
        $page->addShop($this->shop);
        foreach ($this->getLocales() as $locale) {
            /** @var PageTranslation $translation */
            $translation = $page->translate($locale->getCode());
            $translation->setName($name);
            $translation->setSlug(Helper::urlize($name));
            $translation->setContent($this->defaultText);
        }
        
        $page->mergeNewTranslations();
        
        $this->manager->persist($page);
        
        return $page;
    }
1201911
public function isDirectTranslation(PageInterface $page)
    {
        if ($this->originals->contains($page)) {
            return true;
        } elseif ($this->translations->contains($page)) {
            return true;
        }

        return false;
    }
820281
protected function updateSeoPage(PageInterface $pageInterface)
    {
        /** @var SeoPage $seoPage */
        $seoPage = $this->seoPage;

        if ($pageInterface instanceof SnapshotPageProxy) {
            $page = $pageInterface->getPage();
        } else {
            $page = $pageInterface;
        }

        $seoPage->addVar('page_internal', $page);

        $route = $page->getRouteName();

        if ('page_slug' === $route) {
            $seoPage->setLinkCanonical($this->getContainer()->get('router')->generate(
                $route,
                [
                    'path' => $page->getUrl(),
                ],
                0
            ));
        }

        if ('page_slug' === $route
            ||
            '_page_internal_error_not_found' === $route
        ) {
            $seoPage->build();
        }
    }
454355
public function updatePage(
        PageEntity $page,
        $pageData,
        $doFlush = true
    ) {

        if (empty($pageData['modifiedByUserId'])) {
            throw new InvalidArgumentException(
                'Missing needed information (modifiedByUserId) to create page copy.'
            );
        }

        if (empty($pageData['modifiedReason'])) {
            $pageData['modifiedReason'] = 'Update page in ' . get_class($this);
        }

        // Values cannot be changed
        unset($pageData['pageId']);
        unset($pageData['author']);
        unset($pageData['createdDate']);
        unset($pageData['lastPublished']);

        $page->populate($pageData);
        $page->setModifiedByUserId(
            $pageData['modifiedByUserId'],
            $pageData['modifiedReason']
        );

        $this->assertCanUpdateSitePage(
            $page
        );

        $this->getEntityManager()->persist($page);

        if ($doFlush) {
            $this->getEntityManager()->flush($page);
        }

        return $page;
    }
286485
private function pageToArray(PageInterface $page, $locale)
    {
        $tabs = '';
        for ($l=0; $l<$page->getLevel();$l++) {
            $tabs .= ' • ';
        }

        return [
            'value' => $page->getId(),
            'title' => $tabs . $page->translate($locale)->getTitle(),
            'data'  => [
                'locked' => $page->isLocked(),
                'path'   => $this->generateUrl($page->getRoute(), ['_locale' => $locale]),
            ],
        ];
    }
946963
public function getTranslations(string $page, ?string $locale = null): array
    {
        $config = $this->getPageConfig($page);

        $messages = [];
        $catalogue = $this->translatorBag->getCatalogue($locale);

        foreach ($config as $domain => $keys) {
            foreach ($this->getMessages($catalogue, $domain, $keys) as $domainLocale => $messageStrings) {
                if (!$messageStrings) {
                    continue;
                }

                if (!array_key_exists($domainLocale, $messages)) {
                    $messages[$domainLocale] = [];
                }

                $messages[$domainLocale][$domain] = $messageStrings;
            }
        }

        return $messages;

    }
9288
public function addPage($page)
    {
        if (is_array($page)) {
            $page = static::makePage($page);
        } elseif (is_string($page) or is_null($page)) {
            $title = $page;

            $page = app(PageInterface::class);
            $page->setTitle($title);
        }

        if (! ($page instanceof PageInterface)) {
            return;
        }

        $this->getPages()->push($page);

        return $page;
    }
311065
private function orderPages(array $pages, $locale)
    {
        $documentManager = $this->getDocumentManager();

        for ($i = 0; $i < count($pages); ++$i) {
            $document = $documentManager->find($pages[$i], $locale);
            $documentManager->reorder($document, null);
        }
    }
1113751
protected function makeSnapshot(PageInterface $page)
    {
        if (!$this->admin->isGranted('PUBLISH', $page)) {
            return;
        }

        /** @var $pageHelper \Networking\InitCmsBundle\Helper\PageHelper */
        $pageHelper = $this->get('networking_init_cms.helper.page_helper');

        $pageHelper->makePageSnapshot($page);
    }
1069418
public function findByLocale(string $locale): ICollection
	{
		$builder = $this->builder()
			->innerJoin('_pages', '[_locales]', 'l', '_pages.localeId = l.id')
			->andWhere('[url] IS NOT NULL')
			->andWhere('[visible] = %i', 1)
			->andWhere('[l.name] = %s', $locale);
		return $this->toCollection($builder);
	}
56099
private function setPageData(ArticleDocument $document, NodeInterface $node, $locale)
    {
        $pages = [
            [
                'uuid' => $document->getUuid(),
                'title' => $document->getPageTitle() ?: $document->getTitle(),
                'routePath' => $document->getRoutePath(),
                'pageNumber' => $document->getPageNumber(),
            ],
        ];

        foreach ($document->getChildren() as $child) {
            if ($child instanceof ArticlePageDocument
                && LocalizationState::GHOST !== $this->documentInspector->getLocalizationState($child)
            ) {
                $pages[] = [
                    'uuid' => $child->getUuid(),
                    'title' => $child->getPageTitle(),
                    'routePath' => $child->getRoutePath(),
                    'pageNumber' => $child->getPageNumber(),
                ];
            }
        }

        $pages = SortUtils::multisort($pages, '[pageNumber]');

        $document->setPages($pages);
        $node->setProperty(
            $this->propertyEncoder->localizedSystemName(self::PAGES_PROPERTY, $locale),
            json_encode($pages)
        );
    }
526961
private function loadBlocks(PageInterface $page)
    {
        $blocks = $this->blockInteractor->loadPageBlocks($page);

        // save a local cache
        foreach ($blocks as $block) {
            $this->blocks[$block->getId()] = $block;
        }
    }
1290690
private function createOrUpdatePageRoute(RoutablePageBehavior $document, $locale)
    {
        $route = $this->reallocateExistingRoute($document, $locale);
        if ($route) {
            return $route;
        }

        $route = $document->getRoute();
        if (!$route) {
            $route = $this->routeRepository->findByEntity($document->getClass(), $document->getUuid(), $locale);
        }

        if ($route && $route->getEntityId() !== $document->getId()) {
            // Mismatch of entity-id's happens because doctrine don't check entities which has been changed in the
            // current session.

            $document->removeRoute();
            $route = null;
        }

        if ($route) {
            $document->setRoute($route);

            return $this->routeManager->update($document, null, false);
        }

        return $this->routeManager->create($document);
    }
596067
private function loadBlocks(PageInterface $page)
    {
        $i = new \RecursiveIteratorIterator(new RecursiveBlockIterator($page->getBlocks()), \RecursiveIteratorIterator::SELF_FIRST);

        foreach ($i as $block) {
            $this->blocks[$block->getId()] = $block;
        }
    }
250647
protected function copyWebspace($localeSource, $localeDestination)
    {
        $this->output->writeln([
            '------------------------------',
            '<info>Webspace: </info>' . $this->webspaceKeySource . ' => ' . $this->webspaceKeyDestination,
            '<info>Locale: </info>' . $localeSource . ' => ' . $localeDestination,
            '------------------------------',
        ]);

        /** @var HomeDocument $homeDocumentSource */
        $homeDocumentSource = $this->documentManager->find(
            $this->sessionManager->getContentPath($this->webspaceKeySource),
            $localeSource
        );

        // Generate all needed page documents.
        $this->recursiveCopy(
            $homeDocumentSource,
            null,
            $localeDestination
        );

        $this->output->writeln([
            '------------------------------',
            '',
        ]);
    }