public function createNewPageFromTemplate($user, $data)
    {
        if (empty($user)) {
            throw new TrackingException('A valid user is required in ' . get_class($this));
        }
        $validatedData = $data;
        /** @var \Rcm\Entity\Page $page */
        $page = $this->pageRepo->findOneBy(
            [
                'pageId' => $validatedData['page-template'],
                'pageType' => 't'
            ]
        );

        if (empty($page)) {
            throw new PageNotFoundException(
                'No template found for page id: '
                . $validatedData['page-template']
            );
        }

        $pageData = [
            'name' => $validatedData['name'],
            'pageTitle' => $validatedData['pageTitle'],
            'pageType' => 'n', // "n" means "normal"
            'createdByUserId' => $user->getId(),
            'createdReason' => 'New page from template in ' . get_class($this),
            'author' => $user->getName(),
        ];

        $createdPage = $resultRevisionId = $this->pageRepo->copyPage(
            $this->currentSite,
            $page,
            $pageData
        );

        $this->immuteblePageVersionRepo->createUnpublished(
            new PageLocator(
                $this->currentSite->getSiteId(),
                $this->rcmPageNameToPathname->__invoke($createdPage->getName(), $createdPage->getPageType())
            ),
            $this->immutablePageContentFactory->__invoke(
                $createdPage->getPageTitle(),
                $createdPage->getDescription(),
                $createdPage->getKeywords(),
                $this->revisionRepo->find($resultRevisionId)->getPluginWrappers()->toArray()
            ),
            $user->getId(),
            __CLASS__ . '::' . __FUNCTION__
        );
    }
public function createNewPageFromTemplate($user, $data)
    {
        if (empty($user)) {
            throw new TrackingException('A valid user is required in ' . get_class($this));
        }
        $validatedData = $data;
        /** @var \Rcm\Entity\Page $page */
        $page = $this->pageRepo->findOneBy(
            [
                'pageId' => $validatedData['page-template'],
                'pageType' => 't'
            ]
        );

        if (empty($page)) {
            throw new PageNotFoundException(
                'No template found for page id: '
                . $validatedData['page-template']
            );
        }

        $pageData = [
            'name' => $validatedData['name'],
            'pageTitle' => $validatedData['pageTitle'],
            'pageType' => 'n', // "n" means "normal"
            'createdByUserId' => $user->getId(),
            'createdReason' => 'New page from template in ' . get_class($this),
            'author' => $user->getName(),
        ];

        $createdPage = $resultRevisionId = $this->pageRepo->copyPage(
            $this->currentSite,
            $page,
            $pageData
        );

        $this->immuteblePageVersionRepo->createUnpublished(
            new PageLocator(
                $this->currentSite->getSiteId(),
                $this->rcmPageNameToPathname->__invoke($createdPage->getName(), $createdPage->getPageType())
            ),
            $this->immutablePageContentFactory->__invoke(
                $createdPage->getPageTitle(),
                $createdPage->getDescription(),
                $createdPage->getKeywords(),
                $this->revisionRepo->find($resultRevisionId)->getPluginWrappers()->toArray()
            ),
            $user->getId(),
            __CLASS__ . '::' . __FUNCTION__
        );
    }
public function createNewPageFromTemplate ( $ user , $ data ) { if ( empty ( $ user ) ) { throw new TrackingException ( 'A valid user is required in ' . get_class ( $ this ) ) ; } $ validatedData = $ data ; /** @var \Rcm\Entity\Page $page */ $ page = $ this -> pageRepo -> findOneBy ( [ 'pageId' => $ validatedData [ 'page-template' ] , 'pageType' => 't' ] ) ; if ( empty ( $ page ) ) { throw new PageNotFoundException ( 'No template found for page id: ' . $ validatedData [ 'page-template' ] ) ; } $ pageData = [ 'name' => $ validatedData [ 'name' ] , 'pageTitle' => $ validatedData [ 'pageTitle' ] , 'pageType' => 'n' , // "n" means "normal" 'createdByUserId' => $ user -> getId ( ) , 'createdReason' => 'New page from template in ' . get_class ( $ this ) , 'author' => $ user -> getName ( ) , ] ; $ createdPage = $ resultRevisionId = $ this -> pageRepo -> copyPage ( $ this -> currentSite , $ page , $ pageData ) ; $ this -> immuteblePageVersionRepo -> createUnpublished ( new PageLocator ( $ this -> currentSite -> getSiteId ( ) , $ this -> rcmPageNameToPathname -> __invoke ( $ createdPage -> getName ( ) , $ createdPage -> getPageType ( ) ) ) , $ this -> immutablePageContentFactory -> __invoke ( $ createdPage -> getPageTitle ( ) , $ createdPage -> getDescription ( ) , $ createdPage -> getKeywords ( ) , $ this -> revisionRepo -> find ( $ resultRevisionId ) -> getPluginWrappers ( ) -> toArray ( ) ) , $ user -> getId ( ) , __CLASS__ . '::' . __FUNCTION__ ) ; }
Creates a new page from a template. The page starts out "staged" instead of "published".

Note: This code was moved pretty mush as-is from "PageController" and that is why it is a bit messy.

@return Response|ViewModel
@throws TrackingException
Creates a new page from a template . The page starts out staged instead of published .