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
190391
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__
        );
    }
10785
public function createPage(
        SiteEntity $site,
        $pageData,
        $publishPage = false,
        $doFlush = true
    ) {
        if (empty($pageData['createdByUserId'])) {
            throw new PageException('CreatedByUserId is required to create a page.');
        }
        if (empty($pageData['createdReason'])) {
            $pageData['createdReason'] = Tracking::UNKNOWN_REASON;
        }
        if (empty($pageData['author'])) {
            throw new PageException('Author is required to create a page.');
        }
        $revision = new Revision(
            $pageData['createdByUserId'],
            $pageData['createdReason']
        );
        $revision->setAuthor($pageData['author']);

        // we should not have an Id on page create
        unset($pageData['pageId']);

        $page = new PageEntity(
            $pageData['createdByUserId'],
            $pageData['createdReason']
        );
        $page->populate($pageData);

        $page->setSite($site);

        $this->assertCanCreateSitePage(
            $page->getSite(),
            $page->getName(),
            $page->getPageType()
        );

        if (!$publishPage) {
            $page->setStagedRevision($revision);
        } else {
            $page->setPublishedRevision($revision);
        }

        $page->addRevision($revision);

        $this->_em->persist($revision);
        $this->_em->persist($page);

        if ($doFlush) {
            $this->_em->flush(
                [
                    $revision,
                    $page
                ]
            );
        }

        return $page;
    }
965297
public function savePageDraft(
        UserInterface $user,
        string $pageName,
        string $pageType,
        $data,
        $urlToPageFunction,
        int $originalRevisionId
    ) {
        if (empty($user)) {
            throw new TrackingException('A valid user is required in ' . get_class($this));
        }

        $this->prepSaveData($data);

        $result = $this->pageRepo->savePage(
            $this->currentSite,
            $pageName,
            $originalRevisionId,
            $pageType,
            $data,
            $user->getId(),
            'Save existing page in ' . get_class($this),
            $user->getName()
        );

        /**
         * If the pageRepo deterimins there was no change, it saves nothing a returns and empty $resultRevisionId.
         */
        $savedANewVersion = !empty($result['newPageRevisionId']);

        if ($savedANewVersion) {
            $resultPageRevisionId = $result['newPageRevisionId'];
            /**
             * @var Page
             */
            $page = $this->pageRepo->findOneBy([
                'site' => $this->currentSite,
                'name' => $pageName,
                'pageType' => $pageType
            ]);

            $this->immuteblePageVersionRepo->createUnpublished(
                new PageLocator(
                    $this->currentSite->getSiteId(),
                    $this->rcmPageNameToPathname->__invoke($pageName, $pageType)
                ),
                $this->immutablePageContentFactory->__invoke(
                    $page->getPageTitle(),
                    $page->getDescription(),
                    $page->getKeywords(),
                    $this->revisionRepo->find($resultPageRevisionId)->getPluginWrappers()->toArray()
                ),
                $user->getId(),
                __CLASS__ . '::' . __FUNCTION__
            );
        }

        /**
         * @var $container Container
         */
        foreach ($result['modifiedSiteWideContainers'] as $revisionId => $container) {
            $this->immutableSiteWideContainerRepo->publish(
                new SiteWideContainerLocator($container->getSiteId(), $container->getName()),
                new ContainerContent(
                    $this->immutablePageContentFactory->pluginWrappersToFlatBlockInstances(
                        $this->revisionRepo->find($revisionId)->getPluginWrappers()->toArray()
                    )
                ),
                $user->getId(),
                __CLASS__ . '::' . __FUNCTION__
            );
        }

        if ($savedANewVersion) {
            $return['redirect'] = $urlToPageFunction(
                $pageName,
                $pageType,
                $resultPageRevisionId
            );
        } else {
            $return['redirect'] = $urlToPageFunction(
                $pageName,
                $pageType,
                $originalRevisionId
            );
        }

        return $return;
    }
211739
protected function createModel()
    {
        if (! $this->model instanceof \Gems_Tracker_Model_TrackModel) {
            $tracker     = $this->loader->getTracker();
            $this->model = $tracker->getRespondentTrackModel();

            if (! $this->trackEngine instanceof \Gems_Tracker_Engine_TrackEngineInterface) {
                $this->trackEngine = $this->respondentTrack->getTrackEngine();
            }
            $this->model->applyEditSettings($this->trackEngine);
        }

        $this->model->set('restore_tokens', 'label', $this->_('Restore tokens'),
                'description', $this->_('Restores tokens with the same code as the track.'),
                'elementClass', 'Checkbox'
                );

        return $this->model;
    }
967636
private function initStepViewModel() {
        #first start of Wizard
        #load template from first step
        $currentStep = $this->stepCollectionIterator->current();
        $isFirstStep = $this->getSteps()->isFirst($currentStep);
        if ($isFirstStep) {
            $firstStep = $this->getSteps()->getFirst();
            $this->viewModel->addChild($firstStep->getViewModel(), "wizardContent");
            $firstStepFormName = $firstStep->getViewModel()->getVariable("formName", false);
            if (empty($firstStepFormName))
                throw new \Exception("viewModel variable 'formName' must set for Step '".$firstStep->getName()."'");
        }
        if (!($this->prevButtonDisabled && $isFirstStep)) {
            $this->prevButtonViewModel = new ViewModel();
            $this->prevButtonViewModel->setTemplate("wizard/wizardButton");
            $this->prevButtonViewModel->setVariable("stepActionDirection", "prev");
            $this->prevButtonViewModel->setVariable("id", "prevButton");
        }

        $this->nextButtonViewModel = new ViewModel();
        $this->nextButtonViewModel->setTemplate("wizard/wizardButton");
        $this->nextButtonViewModel->setVariable("stepActionDirection", "next");
        $this->nextButtonViewModel->setVariable("id", "nextButton");

        /**
         * creates breadcrumbPath
         */
        $stepIterator = $this->getSteps()->getIterator();
        while ($stepIterator->valid()) {
            $view = $this->createBreadcrumbItems($stepIterator->current());
            $this->getSteps()->isFirst($stepIterator->current()) ? $view->setVariable("extendCssClass", "active first") : false;
            $this->getSteps()->isLast($stepIterator->current()) ? $view->setVariable("extendCssClass", "last") : false;
            $view->setVariable("breadcrumbStepName", $stepIterator->current()->getName());
            $this->viewModel->addChild($view, "breadcrumbNavigation", true);
            $stepIterator->next();
        }
        $this->resultContent = $this->viewModel;
        $this->process();
    }
554386
public function newAction()
    {
        $entity = new WPSetup();
        $form   = $this->createForm(new WPSetupType($this->container), $entity);

        return $this->render('ACSACSPanelWordpressBundle:WPSetup:new.html.twig', array(
            'entity' => $entity,
            'form'   => $form->createView(),
        ));
    }
713416
public function CreatePage() 
	{
		$this->addMenuOption($this->myWords->Value("CREATE_ROLE"), $this->url->getUrl());
		switch ($this->_action)
		{
			case ModuleAction::Create :
			$this->actionCreate();
			break;
			case ModuleAction::CreateConfirm :
			$this->actionSave();
			break;
			case ModuleAction::Delete :
			$this->actionDelete();
			break;
			case ModuleAction::Edit :
			$this->actionEdit();
			break;
			case ModuleAction::EditConfirm :
			$this->actionEditSave();
			break;
			default:
			$this->actionList();
			break;
		}
		
		return $this->defaultXmlnukeDocument->generatePage();
	}
1301837
public function reorderPages()
    {
        if (!$this->request->isAll(['ajax', 'post'])) {
            throw new MethodNotAllowedException();
        }

        if (empty($this->request->data)) {
            throw new BadRequestException();
        }

        $this->request->data = Hash::map($this->request->data, '{n}', function($page) {
            if ($page['parent_id'] === 'null') {
                $page['parent_id'] = null;
            }
            return $page;
        });

        $pages = $this->Pages->patchEntities($this->Pages->find('all'), $this->request->data, ['associated' => false]);

        /** @var Connection $connection */
        $connection = $this->Pages->connection();
        $connection->begin();
        foreach ($pages as $page) {
            $this->Pages->behaviors()->unload('Tree');
            if (!$this->Pages->save($page)) {
                $connection->rollback();
                break;
            }
        }
        if ($connection->inTransaction()) {
            $connection->commit();
            $status = 'success';
            $flashMessage = __d('wasabi_cms', 'The page positions have been updated.');
        } else {
            $status = 'error';
            $flashMessage = $this->dbErrorMessage;
        }

        $this->set([
            'status' => $status,
            'flashMessage' => $flashMessage,
            '_serialize' => ['status', 'flashMessage']
        ]);

        $this->RequestHandler->renderAs($this, 'json');
    }
1365307
public function newAction()
    {
        $entity = new Page();
        $form = $this->createCreateForm($entity);

        return array(
            'entity' => $entity,
            'form' => $form->createView(),
        );
    }
419837
protected function execPageCycle()
    {
        /**
         * @event cms.page.start
         * Fires before all of the page & layout lifecycle handlers are run
         *
         * Example usage:
         *
         *     Event::listen('cms.page.start', function ((\Cms\Classes\Controller) $controller) {
         *         return Response::make('Taking over the lifecycle!', 200);
         *     });
         *
         * Or
         *
         *     $CmsController->bindEvent('page.start', function () {
         *         return Response::make('Taking over the lifecycle!', 200);
         *     });
         *
         */
        if ($event = $this->fireSystemEvent('cms.page.start')) {
            return $event;
        }

        /*
         * Run layout functions
         */
        if ($this->layoutObj) {
            CmsException::mask($this->layout, 300);
            $response = (
                ($result = $this->layoutObj->onStart()) ||
                ($result = $this->layout->runComponents()) ||
                ($result = $this->layoutObj->onBeforePageStart())
            ) ? $result : null;
            CmsException::unmask();

            if ($response) {
                return $response;
            }
        }

        /*
         * Run page functions
         */
        CmsException::mask($this->page, 300);
        $response = (
            ($result = $this->pageObj->onStart()) ||
            ($result = $this->page->runComponents()) ||
            ($result = $this->pageObj->onEnd())
        ) ? $result : null;
        CmsException::unmask();

        if ($response) {
            return $response;
        }

        /*
         * Run remaining layout functions
         */
        if ($this->layoutObj) {
            CmsException::mask($this->layout, 300);
            $response = ($result = $this->layoutObj->onEnd()) ? $result : null;
            CmsException::unmask();
        }

        /**
         * @event cms.page.end
         * Fires after all of the page & layout lifecycle handlers are run
         *
         * Example usage:
         *
         *     Event::listen('cms.page.end', function ((\Cms\Classes\Controller) $controller) {
         *         return Response::make('Taking over the lifecycle!', 200);
         *     });
         *
         * Or
         *
         *     $CmsController->bindEvent('page.end', function () {
         *         return Response::make('Taking over the lifecycle!', 200);
         *     });
         *
         */
        if ($event = $this->fireSystemEvent('cms.page.end')) {
            return $event;
        }

        return $response;
    }
397161
public function createAction()
    {
        if ($this->enableScreens) {
            $edit = false;
            $org  = $this->getRespondent()->getOrganization();
            if (! $org) {
                $org = $this->currentOrganization;
            }

            if ($org) {
                $edit = $org->getRespondentEditScreen();
            }

            if (! $edit) {
                $group = $this->currentUser->getGroup();
                if ($group) {
                    $edit = $group->getRespondentEditScreen();
                }
            }

            if ($edit ) {
                if ($edit instanceof ProcessModelInterface) {
                    $edit->processModel($this->getModel());
                }

                // All are arrays, so easy to set
                $this->createParameters = $edit->getCreateParameters() + $this->createParameters;
                $editSnippets = $edit->getSnippets();
                if (false !== $editSnippets) {
                    $this->createEditSnippets = $editSnippets;
                }
            }
        }

        parent::createAction();
    }
714963
protected function Page()
    {
        if (!$this->page) {
            $this->page = new Page(Request::GetData('page'));
        }
        return $this->page;
    }
429709
public function CreatePage()
	{
		$this->_myWords = $this->WordCollection();

		$title = $this->_myWords->Value("TITLE", $this->_context->get("SERVER_NAME") );
		$abstract = $this->_myWords->Value("ABSTRACT", $this->_context->get("SERVER_NAME") );
		$document = new XmlnukeDocument($title, $abstract);
		
		$this->_url = "module:UserProfile";
				
		$this->_users = $this->getUsersDatabase();
		
		$this->_user = $this->_users->getUserName( $this->_context->authenticatedUser() );
		
		$blockCenterTitle = $this->_myWords->ValueArgs("TITLE", array ($this->_user->getField($this->_users->getUserTable()->username)));
		$blockcenter = new XmlBlockCollection($blockCenterTitle, BlockPosition::Center );
		$document->addXmlnukeObject($blockcenter);
		
		$this->_paragraph = new XmlParagraphCollection();
		$blockcenter->addXmlnukeObject($this->_paragraph);

		$action = $this->_context->get("action");

		switch ($action)
		{
			case "update":
				$this->update();
				break;
			case "changepassword":
				$this->changePWD();
				break;				
		}		
		
		$this->formUserInfo();
		
		$this->formPasswordInfo();
		
		$this->formRolesInfo();	

		return $document->generatePage();
	}
791051
function new_page() {
		//Helpers::dompdf_debug("trace", "()");

		// Add objects to the current page
		$this->_place_objects();

		//$this->_pdf->endPage();
		$this->_pdf->lastPage();

		$this->_pdf->AddPage();
		//$this->_page_count++;
		$this->_pages[] = $this->_pdf->PageNo();
		return $this->_pdf->getNumPages();
	}
213624
function create()
    {
        $content = $this->loadContentTypes();
        $templates = $this->loadTemplates();
        restoreRequest();
        $form = array (
            'name' => 'createPage',
            'caption' => strAdd,
            'width' => '600px',
            'fields' => array (
                array ('type' => 'hidden','name'=>'owner','value'=>arg('owner', 'int')),
                array ('type' => 'hidden','name'=>'action', 'value'=>'insert'),
                array ('type' => 'edit','name' => 'name','label' => admPagesName,'width' => '150px',
                    'maxlength' => '32', 'pattern'=>'/^[a-z0-9_]+$/i', 'errormsg'=>admPagesNameInvalid),
                array ('type' => 'edit','name' => 'title','label' => admPagesTitle,'width' => '100%',
                    'pattern'=>'/.+/', 'errormsg'=>admPagesTitleInvalid),
                array ('type' => 'edit','name' => 'caption','label' => admPagesCaption,'width' => '100%',
                    'maxlength' => '64', 'pattern'=>'/.+/', 'errormsg'=>admPagesCaptionInvalid),
                array ('type' => 'edit','name' => 'hint','label' => admPagesHint,'width' => '100%'),
                array ('type' => 'edit','name' => 'description','label' => admPagesDescription,
                    'width' => '100%'),
                array ('type' => 'edit','name' => 'keywords','label' => admPagesKeywords,'width' => '100%'),
                array ('type' => 'select','name' => 'template','label' => admPagesTemplate,
                    'items' => $templates[0], 'values' => $templates[1], 'default'=>pageTemplateDefault),
                array ('type' => 'select','name' => 'type','label' => admPagesContentType,
                    'items' => $content[0], 'values' => $content[1], 'default'=>contentTypeDefault),
                array ('type' => 'checkbox','name' => 'active','label' => admPagesActive, 'default'=>true),
                array ('type' => 'checkbox','name' => 'visible','label' => admPagesVisible,
                    'default'=>true),
                array ('type' => 'select','name' => 'access','label' => admAccessLevel,'access' => ADMIN,
                    'values'=>array(ADMIN,EDITOR,USER,GUEST),
                    'items' => array (ACCESSLEVEL2,ACCESSLEVEL3,ACCESSLEVEL4,ACCESSLEVEL5),
                    'default' => GUEST),
                array ('type' => 'edit','name' => 'position','label' => admPosition,'access' => ADMIN,
                    'width' => '4em','maxlength' => '5'),
                array ('type' => 'memo','name' => 'options','label' => admPagesOptions,'height' => '5')
            ),
            'buttons' => array('ok', 'cancel'),
        );

        /** @var TAdminUI $page */
        $page = Eresus_Kernel::app()->getPage();
        $result = $page->renderForm($form, Eresus_CMS::getLegacyKernel()->request['arg']);
        return $result;
    }
476411
public function actionCreatePageItem()
    {
        $this->menuFlush();
        $model = new Nav();
        $create = $model->createPageItem($this->postArg('nav_id'), $this->postArg('lang_id'), $this->postArg('title'), $this->postArg('alias'), $this->postArg('layout_id'), $this->postArg('description'));
        if (is_array($create)) {
            Yii::$app->response->statusCode = 422;
        }

        return $create;
    }
683790
public function createView()
    {
        $response = $this->forward('ezpublish_rest.controller.views:createView');

        // Add 301 status code and location href
        $response->setStatusCode(301);
        $response->headers->set('Location', $this->router->generate('ezpublish_rest_views_create'));

        return $response;
    }