setCurrentDomain() public method

public setCurrentDomain ( Domain $domain )
$domain Jarves\Model\Domain
Example #1
0
 /**
  * @ApiDoc(
  *  section="Administration",
  *  description="Returns a renderer content element as preview for Jarves page editor"
  * )
  *
  * @Rest\QueryParam(name="template", requirements=".+", strict=true,
  *      description="The template/view to be used for this content")
  *
  * @Rest\QueryParam(name="type", requirements=".+", strict=true, description="The content type")
  *
  * @Rest\QueryParam(name="nodeId", requirements="[0-9]+",
  *      description="The node id in which context this content should be rendered")
  * @Rest\QueryParam(name="domainId", requirements="[0-9]+",
  *      description="The domain id in which context this content should be rendered")
  * @Rest\RequestParam(name="content", requirements=".*", description="The actual content")
  *
  * @Rest\Post("/admin/content/preview")
  *
  * @param ParamFetcher $paramFetcher
  *
  * @return array
  */
 public function getContentPreviewAction(ParamFetcher $paramFetcher)
 {
     $template = $paramFetcher->get('template');
     $type = $paramFetcher->get('type');
     $content = $paramFetcher->get('content');
     $nodeId = $paramFetcher->get('nodeId');
     $domainId = $paramFetcher->get('domainId');
     //todo, check if $template is defined as content template
     $contentObject = new Content();
     $contentObject->setType($type);
     $contentObject->setTemplate($template);
     $contentObject->setContent($content);
     if ($domainId) {
         $domain = $this->pageStack->getDomain($domainId);
         $this->pageStack->setCurrentDomain($domain);
     }
     if ($nodeId) {
         $page = $this->pageStack->getPage($nodeId);
         $this->pageStack->setCurrentPage($page);
     }
     return $this->contentRender->renderContent($contentObject, ['preview' => true]);
 }
Example #2
0
 public function onKernelRequest(GetResponseEvent $event)
 {
     $request = $event->getRequest();
     if (HttpKernelInterface::MASTER_REQUEST === $event->getRequestType()) {
         //we need to reset all routes. They will anyway replaced by FrontendRouter::loadRoutes,
         //but to prevent caching conflicts, when a user removes a plugin for example
         //from a page, we need to know that without using actual caching.
         $this->routes = new RouteCollection();
         $this->urlMatcher->__construct($this->routes, $this->requestContext);
         //prepare for new master request: clear the PageResponse object
         $this->pageStack->setCurrentPage(null);
         $this->pageStack->setCurrentDomain(null);
         $this->pageStack->setPageResponse($this->pageResponseFactory->create());
         $this->frontendRouter->setRequest($request);
         $editorNodeId = (int) $this->pageStack->getRequest()->get('_jarves_editor_node');
         $editorDomainId = (int) $this->pageStack->getRequest()->get('_jarves_editor_domain');
         $domain = null;
         if ($editorDomainId) {
             $domain = $this->pageStack->getDomain($editorDomainId);
             if (!$domain) {
                 //we haven't found any domain that is responsible for this request
                 return;
             }
             $this->pageStack->setCurrentDomain($domain);
         }
         if ($editorNodeId) {
             //handle jarves content editor stuff
             //access is later checked
             if (!$editorNodeId && $domain) {
                 $editorNodeId = $domain->getStartnodeId();
             }
             $page = $this->pageStack->getPage($editorNodeId);
             if (!$page || !$page->isRenderable()) {
                 //we haven't found any page that is responsible for this request
                 return;
             }
             if (!$domain) {
                 $domain = $this->pageStack->getDomain($page->getDomainId());
             }
             $this->pageStack->setCurrentPage($page);
             $this->pageStack->setCurrentDomain($domain);
             $request->attributes->set('_controller', 'jarves.page_controller:handleAction');
         } else {
             //regular frontend route search
             //search domain
             if (!$domain) {
                 $domain = $this->frontendRouter->searchDomain();
                 if (!$domain) {
                     //we haven't found any domain that is responsible for this request
                     return;
                 }
                 $this->pageStack->setCurrentDomain($domain);
             }
             //search page
             $page = $this->frontendRouter->searchPage();
             if (!$page || !$page->isRenderable()) {
                 //we haven't found any page that is responsible for this request
                 return;
             }
             $this->pageStack->setCurrentPage($page);
             if ($response = $this->frontendRouter->loadRoutes($this->routes, $page)) {
                 //loadRoutes return in case of redirects and permissions a redirect or 404 response.
                 $event->setResponse($response);
                 return;
             }
             try {
                 //check routes in $this->route
                 parent::onKernelRequest($event);
             } catch (MethodNotAllowedException $e) {
             } catch (NotFoundHttpException $e) {
             }
         }
     }
 }