createPage

@param SiteEntity $site
@param array $pageData
@param bool $publishPage
@param bool $doFlush

@return PageEntity
@throws PageException
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;
    }
671668
public function assertCanCreateSitePage(
        SiteEntity $site,
        $pageName,
        $pageType
    ) {
        $allowDuplicates = $this->allowDuplicates($pageType);

        if ($allowDuplicates) {
            return;
        }

        $pageExists = $this->sitePageExists(
            $site,
            $pageName,
            $pageType
        );

        if (!$pageExists) {
            return;
        }

        throw new PageException(
            "Cannot create page: ({$pageName}). " .
            "Duplicate page names not allowed for name: ({$pageName}) type: ({$pageType}) siteId: " .
            '(' . $site->getSiteId() . ')'
        );
    }
719100
public function updatePageWithEntity(BusinessTemplate $page, $entity)
    {
        $page = $this->businessPageBuilder->generateEntityPageFromTemplate($page, $entity, $this->entityManager);
        $this->pageSeoHelper->updateSeoByEntity($page, $entity);

        //update the parameters of the page
        $this->businessPageBuilder->updatePageParametersByEntity($page, $entity);

        return $page;
    }
609961
public function newBlockAction($page_id, $type)
    {
        $em = $this->getDoctrine()->getManager();
        $page = $em->getRepository('AmulenPageBundle:Page')->find($page_id);

        $entity = new Block();
        $entity->setType($type);
        $entity->setPage($page);
        $form = $this->createBlockCreateForm($entity);

        return array(
            'entity' => $entity,
            'form' => $form->createView(),
        );
    }
615528
public static function createFromContent(
        string $content,
        ?InternetMediaTypeInterface $contentType = null,
        ?string $type = null
    ): WebResourceInterface {
        $className = get_called_class();

        return new $className(SitemapProperties::create([
            SitemapProperties::ARG_CONTENT => $content,
            SitemapProperties::ARG_CONTENT_TYPE => $contentType,
            SitemapProperties::ARG_TYPE => $type,
        ]));
    }
483026
public function create($siteId, $userAgent = '', $requestIPAddress = '')
    {
        if (empty($siteId)) {
            throw new \Exception('Cannot create an instance without a site id');
        }

        $cookie = new Cookie();

        $userId = $cookie->getCookie(CookieNames::USER_ID);
        $userId = ! empty($userId) ? $userId : Uuid::v4();

        $payload = new Payload(new Cookie(), $siteId, $userId);

        $requestHeaders = [];

        $browserUserAgent = !empty($userAgent) ? $userAgent : Browser::getUserAgent();
        $browserIPAddress = !empty($requestIPAddress) ? $requestIPAddress : Browser::getRequestIPAddress();

        if (! empty($browserUserAgent)) {
            $requestHeaders['X-Original-User-Agent'] = $browserUserAgent;
        }

        if (! empty($browserIPAddress)) {
            $requestHeaders['X-Original-Request-IP-Address'] = $browserIPAddress;
        }

        $client = new Client([
            'base_uri' => API::ENDPOINT,
            RequestOptions::HEADERS => $requestHeaders,
            RequestOptions::HTTP_ERRORS => false,
            RequestOptions::VERIFY => false
        ]);

        return new Tracker($cookie, $payload, $client);
    }
69321
private function saveEvent($websiteId, $storeId, $type, $entityId, $data)
    {
        $data = $this->json->serialize($data);

        /** @var EventModel $eventModel */
        $eventModel = $this->eventFactory->create()
            ->setEntityId($entityId)
            ->setWebsiteId($websiteId)
            ->setStoreId($storeId)
            ->setEventType($type)
            ->setEventData($data);

        $this->eventRepository->save($eventModel);
    }
55383
public function createPageFooter(
        $page_footer_name = "",
        $line,
        $page_footer_text
    ) {
        if (!$page_footer_name) {
            $page_footer_name = count($this->pageFooters);
        }

        $this->pageFooters[$page_footer_name] = new ReporticoPageEnd($line, $page_footer_text);
    }
443012
protected function writeTOC($publishPages = false, $preservedDocument = null)
    {
        $page = $this->form->getRecord();
        $content = '<ul>';

        if ($page) {
            if ($page->Children()->Count() > 0) {
                foreach ($page->Children() as $child) {
                    $content .= '<li><a href="' . $child->Link() . '">' . $child->Title . '</a></li>';
                }
                $page->Content = $content . '</ul>';
            } else {
                $doc = new DOMDocument();
                $doc->loadHTML($page->Content);
                $body = $doc->getElementsByTagName('body')->item(0);
                $node = $body->firstChild;
                $h1 = $h2 = 1;
                while ($node) {
                    if ($node instanceof DOMElement && $node->tagName == 'h1') {
                        $content .= '<li><a href="#h1.' . $h1 . '">' .
                            trim(preg_replace('/\n|\r/', '', Convert::html2raw($node->textContent))) .
                            '</a></li>';
                        $node->setAttributeNode(new DOMAttr("id", "h1.".$h1));
                        $h1++;
                    } elseif ($node instanceof DOMElement && $node->tagName == 'h2') {
                        $content .= '<li class="menu-h2"><a href="#h2.' . $h2 . '">' .
                            trim(preg_replace('/\n|\r/', '', Convert::html2raw($node->textContent))) .
                            '</a></li>';
                        $node->setAttributeNode(new DOMAttr("id", "h2.".$h2));
                        $h2++;
                    }
                    $node = $node->nextSibling;
                }
                $page->Content = $content . '</ul>' . $doc->saveHTML();
            }

            // Add in the link to the original document, if provided.
            if ($preservedDocument) {
                $page->Content = '<a href="' .
                    $preservedDocument->Link() .
                    '" title="download original document">download original document (' .
                    $preservedDocument->getSize() .
                    ')</a>' .
                    $page->Content;
            }

            // Store the result
            $page->write();
            if ($publishPages) {
                $page->publishRecursive();
            }
        }
    }
354912
public function addForm(FormBuilderInterface $fb, Page $page)
    {
        $data = $page->getData() == "" ? 0 : $page->getData();
        $fb->add('mode', ChoiceType::class,[
            "label" => "sitemap.behavior",
            "translation_domain" => "forms",
            "choices" => [
                "sitemap.absolute" => 0,
                "sitemap.relative" => 1,
                "sitemap.subpages" => 2,
            ],
            "data" => $data["mode"],
            "mapped" => false
        ])
            ->add("limit", NumberType::class, [
                "label" => "sitemap.limit",
                "translation_domain" => "forms",
                "mapped" => false,
                "data" => $data["limit"],
                "required" => false
            ]);
        return $fb;
    }
649858
public function handlePublish(PublishEvent $event)
    {
        $document = $event->getDocument();
        if (!$document instanceof RoutableBehavior) {
            return;
        }

        $node = $this->documentInspector->getNode($document);

        try {
            $route = $this->createOrUpdateRoute($document, $event->getLocale());
        } catch (RouteIsNotUniqueException $exception) {
            throw new ResourceLocatorAlreadyExistsException($exception->getRoute()->getPath(), $document->getPath());
        }

        $document->setRoutePath($route->getPath());
        $this->entityManager->persist($route);

        $node->setProperty(
            $this->getRoutePathPropertyName($document->getStructureType(), $event->getLocale()),
            $route->getPath()
        );

        $propertyName = $this->getPropertyName($event->getLocale(), self::ROUTES_PROPERTY);

        // check if nodes previous generated routes exists and remove them if not
        $oldRoutes = $event->getNode()->getPropertyValueWithDefault($propertyName, []);
        $this->removeOldChildRoutes($event->getNode()->getSession(), $oldRoutes, $event->getLocale());

        $routes = [];
        if ($document instanceof ChildrenBehavior) {
            // generate new routes of children
            $routes = $this->generateChildRoutes($document, $event->getLocale());
        }

        // save the newly generated routes of children
        $event->getNode()->setProperty($propertyName, $routes);
        $this->entityManager->flush();
    }
330347
private function createSitePage($siteName, $fatherId, $siteLangId, $pageType, $pageId, $templateId, $platformId)
	{
	    // Event parameters prepare
	    $arrayParameters = $this->makeArrayFromParameters(__METHOD__, func_get_args());
	    
	    // Sending service start event
	    $arrayParameters = $this->sendEvent('meliscmssite_service_save_site_page_start', $arrayParameters);
	    
	    // Service implementation start
	   
	    $pageTreeTable = $this->getServiceLocator()->get('MelisEngineTablePageTree');
	    $pageLangTable = $this->getServiceLocator()->get('MelisEngineTablePageLang');
	    $pageSavedTable = $this->getServiceLocator()->get('MelisEngineTablePageSaved');
	    $cmsPlatformTable = $this->getServiceLocator()->get('MelisEngineTablePlatformIds');
	    
	    /**
	     * Retrieving the Current Page tree
	     * with Father Id of -1 "root node of the page tree"
	     * to get the Order of the new entry
	     */
	    $treePageOrder = $pageTreeTable->getTotalData('tree_father_page_id', $fatherId);
	    // Saving Site page on Page tree
	    $pageTreeTable->save(array(
	        'tree_page_id' => $arrayParameters['pageId'],
	        'tree_father_page_id' => $fatherId,
	        'tree_page_order' => $treePageOrder + 1,
	    ));
	     
	    // Saving Site page Language
	    $pageLangTable->save(array(
	        'plang_page_id' => $arrayParameters['pageId'],
	        'plang_lang_id' => $arrayParameters['siteLangId'],
	        'plang_page_id_initial' => $arrayParameters['pageId']
	    ));
	    
	    // Saving Site page in Save Version as new page entry
	    $pageSavedTable->save(array(
	        'page_id' => $arrayParameters['pageId'],
	        'page_type' => $arrayParameters['pageType'],
	        'page_status' => 1,
	        'page_menu' => 'LINK',
	        'page_name' => $arrayParameters['siteName'],
	        'page_tpl_id' => $arrayParameters['templateId'],
	        'page_content' => '<?xml version="1.0" encoding="UTF-8"?><document type="MelisCMS" author="MelisTechnology" version="2.0"></document>',
	        'page_taxonomy' => '',
	        'page_creation_date' => date('Y-m-d H:i:s')
	    ));
	    
	    // Updating platform ids after site pages creation
	    $platform = array(
           'pids_page_id_current' => ++$arrayParameters['pageId']
        );
	    $cmsPlatformTable->save($platform, $arrayParameters['platformId']);
	    
	    // Service implementation end
	    
	    // Adding results to parameters for events treatment if needed
	    $arrayParameters['results'] = $arrayParameters['pageId'];
	    // Sending service end event
	    $arrayParameters = $this->sendEvent('meliscmssite_service_save_site_page_end', $arrayParameters);
	    
	    return $arrayParameters['results'];
	}
856662
public function create(PageRequest $request)
    {

        $page = $this->repository->newInstance([]);
        return $this->response->setMetaTitle(trans('app.new') . ' ' . trans('page::page.name')) 
            ->view('page::page.create', true) 
            ->data(compact('page'))
            ->output();
    }
89377
public function createContainer(
        SiteEntity $site,
        string $name,
        string $createdByUserId,
        string $createdReason = Tracking::UNKNOWN_REASON,
        $author = Tracking::UNKNOWN_AUTHOR
    ) {
        $container = new ContainerEntity(
            $createdByUserId,
            $createdReason
        );
        $container->setName($name);
        $container->setSite($site);
        $container->setAuthor($author);

        $this->_em->persist($container);
        $this->_em->flush($container);

        return $container;
    }
1302330
function createPage(ref, user) {
  const NOW = new Date().toISOString(),
    users = [userOrRobot(user)],
    meta = {
      createdAt: NOW,
      archived: false,
      published: false,
      publishTime: null,
      updateTime: null,
      urlHistory: [],
      firstPublishTime: null,
      url: '',
      title: '',
      authors: [],
      users,
      history: [{action: 'create', timestamp: NOW, users }],
      siteSlug: sitesService.getSiteFromPrefix(ref.substring(0, ref.indexOf('/_pages'))).slug
    };

  return putMeta(ref, meta);
}
1173289
public function sitePageExists(
        SiteEntity $site,
        $pageName,
        $pageType
    ) {
        try {
            $page = $this->getPageByName(
                $site,
                $pageName,
                $pageType
            );
        } catch (\Exception $e) {
            $page = null;
        }

        return !empty($page);
    }
597965
public function buildPageQuery($pageId)
    {
        $siteRepository = GeneralUtility::makeInstance(SiteRepository::class);
        $site = $siteRepository->getSiteByPageId($pageId);

        return $this->newSearchQuery('')
            ->useQueryString('*:*')
            ->useFilter('(type:pages AND uid:' . $pageId . ') OR (*:* AND pid:' . $pageId . ' NOT type:pages)', 'type')
            ->useFilter('siteHash:' . $site->getSiteHash(), 'siteHash')
            ->useReturnFields(ReturnFields::fromString('*'))
            ->useSortings(Sortings::fromString('type asc, title asc'))
            ->useQueryType('standard')
            ->getQuery();
    }