/** * Filter the `core.request` event to decorated the action * * @param GetResponseEvent $event * * @return void * * @throws InternalErrorException * @throws PageNotFoundException */ public function onCoreRequest(GetResponseEvent $event) { $request = $event->getRequest(); $cms = $this->cmsSelector->retrieve(); if (!$cms) { throw new InternalErrorException('No CMS Manager available'); } // true cms page if ($request->get('_route') == PageInterface::PAGE_ROUTE_CMS_NAME) { return; } if (!$this->decoratorStrategy->isRequestDecorable($request)) { return; } $site = $this->siteSelector->retrieve(); if (!$site) { throw new InternalErrorException('No site available for the current request with uri ' . htmlspecialchars($request->getUri(), ENT_QUOTES)); } if ($site->getLocale() && $site->getLocale() != $request->get('_locale')) { throw new PageNotFoundException(sprintf('Invalid locale - site.locale=%s - request._locale=%s', $site->getLocale(), $request->get('_locale'))); } try { $page = $cms->getPageByRouteName($site, $request->get('_route')); if (!$page->getEnabled() && !$this->cmsSelector->isEditor()) { throw new PageNotFoundException(sprintf('The page is not enabled : id=%s', $page->getId())); } $cms->setCurrentPage($page); } catch (PageNotFoundException $e) { return; } }
/** * {@inheritdoc} */ public function getBaseUrl() { $site = $this->selector->retrieve(); if ($site) { return parent::getBaseUrl() . $site->getRelativePath(); } return parent::getBaseUrl(); }
public function onLateKernelRequest(GetResponseEvent $event) { $site = $this->siteSelector->retrieve(); if ($site) { $this->translatableListener->setTranslatableLocale($site->getLocale()); $this->translatableListener->setFallbackLocales($site->getLocales()); } }
public function generatePageMenu($menu) { $site = $this->site_selector->retrieve(); $page = $this->page_manager->getPageByUrl($site, '/'); $menu->addChild($page->getName(), array('route' => $page->getRouteName(), 'routeParameters' => array('path' => $page->getUrl()))); if (!$page) { return false; } $this->iterate($menu[$page->getName()], $page); }
/** * {@inheritdoc} */ public function execute(BlockContextInterface $blockContext, Response $response = null) { $settings = $blockContext->getSettings(); $cmsManager = $this->cmsManagerSelector->retrieve(); if ($settings['current']) { $page = $cmsManager->getCurrentPage(); } elseif ($settings['pageId']) { $page = $settings['pageId']; } else { try { $page = $cmsManager->getPage($this->siteSelector->retrieve(), '/'); } catch (PageNotFoundException $e) { $page = false; } } return $this->renderResponse($blockContext->getTemplate(), array('page' => $page, 'block' => $blockContext->getBlock(), 'settings' => $settings), $response); }
/** * Forwards pathInfo to subrequests. * Allows HostPathSiteSelector to work. * * @param string $controller * @param array $attributes * @param array $query * * @return ControllerReference */ public function controller($controller, $attributes = array(), $query = array()) { $globals = $this->environment->getGlobals(); if (!isset($attributes['pathInfo'])) { $sitePath = $this->siteSelector->retrieve()->getRelativePath(); $currentPathInfo = $globals['app']->getRequest()->getPathInfo(); $attributes['pathInfo'] = $sitePath . $currentPathInfo; } return $this->httpKernelExtension->controller($controller, $attributes, $query); }
/** * Handles a kernel exception. * * @param GetResponseForExceptionEvent $event * * @throws \Exception */ public function onKernelException(GetResponseForExceptionEvent $event) { if ($event->getException() instanceof NotFoundHttpException && $this->cmsManagerSelector->isEditor()) { $pathInfo = $event->getRequest()->getPathInfo(); // can only create a CMS page, so the '_route' must be null $creatable = !$event->getRequest()->get('_route') && $this->decoratorStrategy->isRouteUriDecorable($pathInfo); if ($creatable) { $response = new Response($this->templating->render('SonataPageBundle:Page:create.html.twig', array('pathInfo' => $pathInfo, 'site' => $this->siteSelector->retrieve(), 'creatable' => $creatable)), 404); $event->setResponse($response); $event->stopPropagation(); return; } } if ($event->getException() instanceof InternalErrorException) { $this->handleInternalError($event); } else { $this->handleNativeError($event); } }
/** * Gets the site from site selector. * * @return Site|null */ protected function getSite() { return $this->siteSelector->retrieve(); }
/** * Retrieves a page object from a page alias. * * @param string $alias * * @return \Sonata\PageBundle\Model\PageInterface|null * * @throws PageNotFoundException */ protected function getPageByPageAlias($alias) { $site = $this->siteSelector->retrieve(); $page = $this->cmsSelector->retrieve()->getPageByPageAlias($site, $alias); return $page; }