@param PageInterface              $draftPage
@param \JMS\Serializer\Serializer $serializer

@return PageInterface
975785
public function revertToPublished(PageInterface $draftPage, \JMS\Serializer\SerializerInterface $serializer)
    {
        $pageSnapshot = $draftPage->getSnapshot();
        $contentRoute = $draftPage->getContentRoute();

        /** @var $publishedPage PageInterface */
        $publishedPage = $serializer->deserialize(
            $pageSnapshot->getVersionedData(),
            $this->getClassName(),
            'json'
        );

        // Save the layout blocks in a temp variable so that we can
        // assure the correct layout blocks will be saved and not
        // merged with the layout blocks from the draft page
        $tmpLayoutBlocks = $publishedPage->getLayoutBlock();

	    // tell the entity manager to handle our published page
	    // as if it came from the DB and not a serialized object
	    $publishedPage = $this->_em->merge($publishedPage);



        $contentRoute->setTemplate($pageSnapshot->getContentRoute()->getTemplate());
        $contentRoute->setTemplateName($pageSnapshot->getContentRoute()->getTemplateName());
        $contentRoute->setController($pageSnapshot->getContentRoute()->getController());
        $contentRoute->setPath($pageSnapshot->getContentRoute()->getPath());

        $this->_em->merge($contentRoute);

        $publishedPage->setContentRoute($contentRoute);

        // Set the layout blocks of the NOW managed entity to
        // exactly that of the published version
	    foreach ($tmpLayoutBlocks as $key => $layoutBlock){

		    try{
			    $layoutBlock = $this->_em->merge($layoutBlock);
		    }catch (EntityNotFoundException $e){
		    	$layoutBlock = clone $layoutBlock;
		    	$this->_em->persist($layoutBlock);
		    }

		    $this->resetContent($publishedPage, $layoutBlock, $serializer);

		    $tmpLayoutBlocks->set($key, $layoutBlock);
	    }

	    $publishedPage->resetLayoutBlock($tmpLayoutBlocks);
	    $this->_em->persist($publishedPage);
        $this->_em->flush();

        return $publishedPage;
    }
1135537
public static function get(
        int $draftShareInviteApiKeyId,
        array $customHeaders = []
    ): BunqResponseDraftShareInviteApiKey {
        $apiClient = new ApiClient(static::getApiContext());
        $responseRaw = $apiClient->get(
            vsprintf(
                self::ENDPOINT_URL_READ,
                [static::determineUserId(), $draftShareInviteApiKeyId]
            ),
            [],
            $customHeaders
        );

        return BunqResponseDraftShareInviteApiKey::castFromBunqResponse(
            static::fromJson($responseRaw, self::OBJECT_TYPE_GET)
        );
    }
1302496
public function handleForm(FormPageInterface $page, Request $request, RenderContext $context)
    {
        /* @var $em EntityManager */
        $em = $this->container->get('doctrine.orm.entity_manager');
        /* @var $formBuilder FormBuilderInterface */
        $formBuilder = $this->container->get('form.factory')->createBuilder(FormType::class);
        /* @var $router RouterInterface */
        $router = $this->container->get('router');
        /* @var $fields ArrayObject */
        $fields = new ArrayObject();
        $pageParts = $em->getRepository('KunstmaanPagePartBundle:PagePartRef')->getPageParts($page, $page->getFormElementsContext());
        foreach ($pageParts as $sequence => $pagePart) {
            if ($pagePart instanceof FormAdaptorInterface) {
                $pagePart->adaptForm($formBuilder, $fields, $sequence);
            }
        }

        $form = $formBuilder->getForm();
        if ($request->getMethod() == 'POST') {
            $form->handleRequest($request);
            if ($form->isSubmitted() && $form->isValid()) {
                $formSubmission = new FormSubmission();
                $formSubmission->setIpAddress($request->getClientIp());
                $formSubmission->setNode($em->getRepository('KunstmaanNodeBundle:Node')->getNodeFor($page));
                $formSubmission->setLang($request->getLocale());
                $em->persist($formSubmission);

                /* @var $field FormSubmissionField */
                foreach ($fields as $field) {
                    $field->setSubmission($formSubmission);
                    $field->onValidPost($form, $formBuilder, $request, $this->container);
                    $em->persist($field);
                }

                $em->flush();
                $em->refresh($formSubmission);

                $event = new SubmissionEvent($formSubmission, $page);
                $this->container->get('event_dispatcher')->dispatch(FormEvents::ADD_SUBMISSION, $event);

                return new RedirectResponse($page->generateThankYouUrl($router, $context));
            }
        }
        $context['frontendform'] = $form->createView();
        $context['frontendformobject'] = $form;

        return null;
    }
495050
public function getPageAction($requestId, $page) {
        $response = $this->loadPage($requestId, $page);
        $response['toolbar'] = $this->container->get('mesd.jasper.reportviewer.linkhelper')->generateToolbarLinks(
            $requestId, $response['page'], $response['totalPages']);

        return new JsonResponse($response);
    }
570905
public function updateRoleDraft($roleId, Request $request)
    {
        $createStruct = $this->inputDispatcher->parse(
            new Message(
                array('Content-Type' => $request->headers->get('Content-Type')),
                $request->getContent()
            )
        );

        try {
            // First try to load the draft for given role.
            $roleDraft = $this->roleService->loadRoleDraftByRoleId($roleId);
        } catch (NotFoundException $e) {
            // We might want a newly created role, so try to load it by its ID.
            // loadRoleDraft() might throw a NotFoundException (wrong $roleId). If so, let it bubble up.
            $roleDraft = $this->roleService->loadRoleDraft($roleId);
        }

        return $this->roleService->updateRoleDraft($roleDraft, $this->mapToUpdateStruct($createStruct));
    }
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;
    }
896426
public static function createPage(UtilityContext $context, string $pageName, ?string ...$parameters)
    {
        /* Note: no return type to enable type-hinting */

        if (self::$factory === null) {
            self::$factory = self::getFactory(self::$installType);
        }

        return self::$factory::createPage($context, $pageName, ...$parameters);
    }
260685
public function getPageRevisionList($siteId, $pageName, $pageType)
    {
        $publishedQueryBuilder = $this->_em->createQueryBuilder();

        $publishedQueryBuilder->select('PARTIAL page.{pageId}, published, staged ')
            ->from(\Rcm\Entity\Page::class, 'page')
            ->leftjoin('page.publishedRevision', 'published')
            ->leftjoin('page.stagedRevision', 'staged')
            ->where('page.site = :siteId')
            ->andWhere('page.name = :pageName')
            ->andWhere('page.pageType = :pageType')
            ->setParameter('siteId', $siteId)
            ->setParameter('pageName', $pageName)
            ->setParameter('pageType', $pageType);

        $lastDraftQueryBuilder = $this->getRevisionQuery(
            $siteId,
            $pageName,
            $pageType
        );

        $result = $publishedQueryBuilder->getQuery()->getSingleResult(
            \Doctrine\ORM\Query::HYDRATE_ARRAY
        );

        try {
            $lastDraft = $lastDraftQueryBuilder->setMaxResults(1)->getSingleResult(
                \Doctrine\ORM\Query::HYDRATE_ARRAY
            );
            $lastDraft = array_values($lastDraft['revisions']);
        } catch (NoResultException $e) {
            $lastDraft = [0 => null];
        }

        $result['lastDraft'] = $lastDraft[0];

        if ($result['lastDraft']['revisionId']
            == $result['stagedRevision']['revisionId']
        ) {
            $result['lastDraft'] = null;
        }

        return $result;
    }
438224
public function addForm(FormBuilderInterface $fb, Page $page)
    {
        if(!is_array($page->getData())){
            $page->setData([
                "link"=>$page->getData(),
                "code"=>302
            ]);
        }
        $fb->add("link", TextType::class, [
            "label" => "link.link",
            "translation_domain"=>"forms",
            "mapped"=> false,
            "data" => $page->getData()["link"]
        ])
            ->add("code", ChoiceType::class, [
                "label" => "link.redirect",
                "choices" => [
                    "link.found" => RedirectResponse::HTTP_FOUND,
                    "link.moved_permanently" => RedirectResponse::HTTP_MOVED_PERMANENTLY,
                ],
                "translation_domain"=>"forms",
                "choice_translation_domain"=>"forms",
                "mapped"=>false,
                "data"=> $page->getData()["code"]
            ]);
        return $fb;
    }
472957
protected static function sort(JsonApiSerializer $serializer, Builder $builder, Model $model)
    {
        $mapping = $serializer->getTransformer()->getMappingByClassName(get_class($model));
        $sorts = RequestFactory::create()->getSort()->sorting();

        if (!empty($sorts)) {
            $aliased = $mapping->getAliasedProperties();

            $sortsFields = str_replace(array_values($aliased), array_keys($aliased), array_keys($sorts));
            $sorts = array_combine($sortsFields, array_values($sorts));

            foreach ($sorts as $field => $direction) {
                $builder->orderBy($field, ($direction === 'ascending') ? 'ASC' : 'DESC');
            }
        }

        return $builder;
    }
926608
public static function make_draftfile_url($draftid, $pathname, $filename, $forcedownload = false) {
        global $CFG, $USER;
        $urlbase = "$CFG->wwwroot/draftfile.php";
        $context = context_user::instance($USER->id);

        return self::make_file_url($urlbase, "/$context->id/user/draft/$draftid".$pathname.$filename, $forcedownload);
    }
1670
protected static function prepareSerializer(SerializerInterface $serializer = null)
    {
        if (null === $serializer) {
            $serializer = SerializerFactory::create();
        }

        return $serializer;
    }
416645
public static function get(int $draftShareInviteBankId, array $customHeaders = []): BunqResponseDraftShareInviteBank
    {
        $apiClient = new ApiClient(static::getApiContext());
        $responseRaw = $apiClient->get(
            vsprintf(
                self::ENDPOINT_URL_READ,
                [static::determineUserId(), $draftShareInviteBankId]
            ),
            [],
            $customHeaders
        );

        return BunqResponseDraftShareInviteBank::castFromBunqResponse(
            static::fromJson($responseRaw, self::OBJECT_TYPE_GET)
        );
    }
518349
public function Delete($DraftID = '', $TransientKey = '') {
      $Form = Gdn::Factory('Form');
      $Session = Gdn::Session();
      if (
         is_numeric($DraftID)
         && $DraftID > 0
         && $Session->UserID > 0
         && $Session->ValidateTransientKey($TransientKey)
      ) {
         // Delete the draft
         $Draft = $this->DraftModel->GetID($DraftID);
         if ($Draft && !$this->DraftModel->Delete($DraftID))
            $Form->AddError('Failed to delete discussion');
      } else {
         // Log an error
         $Form->AddError('ErrPermission');
      }
      
      // Redirect
      if ($this->_DeliveryType === DELIVERY_TYPE_ALL) {
         $Target = GetIncomingValue('Target', '/vanilla/drafts');
         Redirect($Target);
      }
      
      // Return any errors  
      if ($Form->ErrorCount() > 0)
         $this->SetJson('ErrorMessage', $Form->Errors());
      
      // Render default view
      $this->Render();         
   }
477749
public function GetID($DraftID) {
      $this->DraftQuery();
      return $this->SQL
         ->Where('d.DraftID', $DraftID)
         ->Get()
         ->FirstRow();
   }
1301048
public function save(BlockInterface $block, $draft = true)
    {
        $this->setDraftVersionFilter(! $draft);
        $block->setDraft($draft);

        $this->em->persist($block);
        $this->em->flush($block);

        return $this;
    }
827751
def publish(self, page):
        
        assert page.publisher_is_draft == True, "Page '%s' must be a draft!" % page
        publish_page(page, languages=self.languages)