Ejemplo n.º 1
0
 /**
  * Set the active theme if there is a portal.
  *
  * @param GetResponseEvent $event
  */
 public function onKernelRequest(GetResponseEvent $event)
 {
     $portal = $this->requestAnalyzer->getPortal();
     if (null === $portal) {
         return;
     }
     $themeKey = $portal->getWebspace()->getTheme()->getKey();
     $this->activeTheme->setName($themeKey);
 }
 /**
  * @param GetResponseEvent $event
  */
 public function onKernelRequest(GetResponseEvent $event)
 {
     $request = $event->getRequest();
     if ($this->router instanceof I18nRouter) {
         $collection = $this->router->getOriginalRouteCollection();
     } else {
         $collection = $this->router->getRouteCollection();
     }
     $route = $collection->get($request->get('_route'));
     if (!empty($route) && $route->hasOption('theme_group')) {
         $group = $route->getOption('theme_group');
         $this->theme->setName($group . '_' . $this->container->getParameter('vsymfo_core.theme_' . $group));
     }
 }
 public function testWithoutParams()
 {
     $activeTheme = new ActiveTheme('b', array('a', 'b'));
     $activeTheme->setName('a');
     $listener = new ThemeControllerListener($activeTheme);
     $listener->onKernelRequest($this->getResponseEventMock());
     $this->assertFalse($this->request->attributes->has('_controller'));
     $this->assertFalse($this->request->attributes->has('_route_params'));
 }
 /**
  * {@inheritdoc}
  */
 public function onKernelException(GetResponseForExceptionEvent $event)
 {
     $isPanel = false;
     foreach ($this->accessMap->getPatterns($event->getRequest()) as $pattern) {
         if (is_array($pattern)) {
             foreach ($pattern as $role) {
                 if (is_string($role) && $role === 'ROLE_PANEL_ACCESS') {
                     $isPanel = true;
                     break;
                 }
             }
         }
     }
     if ($isPanel) {
         $this->activeTheme->setName('backend_' . $this->backendTheme);
     }
     $this->loginBlockedException($event);
 }
Ejemplo n.º 5
0
 private function loadStructures($webspaceKey)
 {
     $before = $this->activeTheme->getName();
     $webspace = $this->webspaceManager->findWebspaceByKey($webspaceKey);
     $this->activeTheme->setName($webspace->getTheme()->getKey());
     $structures = [];
     $keys = [];
     foreach ($this->structureManager->getStructures() as $page) {
         /* @var PageBridge $page */
         $template = sprintf('%s.html.twig', $page->getView());
         if ($this->templateExists($template)) {
             $keys[] = $page->getKey();
             $structures[] = $page;
         }
     }
     $this->activeTheme->setName($before);
     $this->cache->save($webspaceKey, $keys);
     return $structures;
 }
Ejemplo n.º 6
0
 /**
  * renders content with the real website controller.
  *
  * @param PageBridge $content
  * @param bool       $partial
  *
  * @return string
  */
 public function render(PageBridge $content, $partial = false)
 {
     // set active theme
     $webspace = $this->webspaceManager->findWebspaceByKey($content->getWebspaceKey());
     $this->activeTheme->setName($webspace->getTheme()->getKey());
     // get controller and invoke action
     $request = new Request();
     $request->attributes->set('_controller', $content->getController());
     $controller = $this->controllerResolver->getController($request);
     // prepare locale for translator and request
     $request->setLocale($content->getLanguageCode());
     $localeBefore = $this->translator->getLocale();
     $this->translator->setLocale($content->getLanguageCode());
     $this->requestStack->push($request);
     /** @var Response $response */
     $response = $controller[0]->{$controller[1]}($content, true, $partial);
     // roll back
     $this->requestStack->pop();
     $this->translator->setLocale($localeBefore);
     return $response->getContent();
 }
 /**
  * @param GetResponseEvent $event
  */
 public function onKernelRequest(GetResponseEvent $event)
 {
     if (HttpKernelInterface::MASTER_REQUEST === $event->getRequestType()) {
         if ($this->autoDetect) {
             $this->autoDetect->setUserAgent($event->getRequest()->server->get('HTTP_USER_AGENT'));
         }
         $cookieValue = null;
         if (null !== $this->cookieOptions) {
             $cookieValue = $event->getRequest()->cookies->get($this->cookieOptions['name']);
         }
         if (!$cookieValue && $this->autoDetect instanceof DeviceDetectionInterface) {
             $cookieValue = $this->autoDetect->getType();
         }
         if ($cookieValue && $cookieValue !== $this->activeTheme->getName() && in_array($cookieValue, $this->activeTheme->getThemes())) {
             $this->activeTheme->setName($cookieValue);
             // store into cookie
             if ($this->cookieOptions) {
                 $this->newTheme = $cookieValue;
             }
         }
     }
 }
Ejemplo n.º 8
0
 /**
  * @contain Liip\ThemeBundle\Locator\FileLocator::locate
  */
 public function testLocateActiveThemeUpdate()
 {
     $kernel = $this->getKernelMock();
     $activeTheme = new ActiveTheme('foo', array('foo', 'bar', 'foobar'));
     $fileLocator = new FileLocatorFake($kernel, $activeTheme, $this->getFixturePath() . '/rootdir/Resources');
     $this->assertEquals('foo', $fileLocator->lastTheme);
     $activeTheme->setName('bar');
     $fileLocator->locate('Resources/themes/foo/template', $this->getFixturePath(), true);
     $this->assertEquals('bar', $fileLocator->lastTheme);
 }
Ejemplo n.º 9
0
 /**
  * {@inheritdoc}
  */
 public function setName($name)
 {
     $this->init();
     parent::setName($name);
 }
Ejemplo n.º 10
0
 /**
  * @expectedException InvalidArgumentException
  * @covers Liip\ThemeBundle\ActiveTheme::setName
  */
 public function testSetInvalidName()
 {
     $theme = new ActiveTheme('foo', array('foo'));
     $theme->setName('bar');
 }