Inheritance: extends ThemeContent
コード例 #1
0
ファイル: PageResponse.php プロジェクト: jarves/jarves
 /**
  * Builds the html body of the current page.
  *
  * @return string
  * @throws \Exception
  */
 public function buildBody()
 {
     $this->stopwatch->start('Build PageBody');
     if (!($page = $this->pageStack->getCurrentPage())) {
         $this->stopwatch->stop('Build PageBody');
         return '';
     }
     $themeId = $page->getTheme();
     if (!$themeId && $this->pageStack->getCurrentDomain()) {
         $themeId = $this->pageStack->getCurrentDomain()->getTheme();
     }
     if (!$themeId) {
         throw new \LogicException('PageResponse class was not able to find a theme to use for rendering the body. Define one at the currentPage or currentDomain of PageStack.');
     }
     if (!($theme = $this->jarves->getConfigs()->getTheme($themeId))) {
         $this->stopwatch->stop('Build PageBody');
         throw new \LogicException(sprintf('Theme `%s` not found.', $themeId));
     }
     $layoutKey = $this->getLayout($page);
     $layout = $theme->getLayoutByKey($layoutKey);
     if ('_tray' === $layoutKey && !$layout) {
         $layout = new ThemeLayout();
         $layout->setFile('JarvesBundle:Default:tray.html.twig');
     }
     if (!$layout) {
         $this->stopwatch->stop('Build PageBody');
         throw new \LogicException(sprintf('Layout for `%s` in theme `%s` not found.', $layoutKey, $themeId));
     }
     $layoutPath = $layout->getFile();
     try {
         $html = $this->templating->render($layoutPath, $this->getPageViewParameter());
     } catch (\Exception $e) {
         throw new \Exception(sprintf('Cant render view `%s` of theme `%s`.', $layoutPath, $themeId), 0, $e);
     }
     $this->stopwatch->stop('Build PageBody');
     return $html;
 }
コード例 #2
0
ファイル: BundleConfigTest.php プロジェクト: jarves/jarves
    public function testTheme()
    {
        $xml = '<theme id="jarvesDemoTheme">
  <label>Jarves cms Demo Theme</label>
  <contents>
    <content>
      <label>Default</label>
      <file>@JarvesDemoThemeBundle/content_default.tpl</file>
    </content>
    <content>
      <label>Sidebar Item</label>
      <file>@JarvesDemoThemeBundle/content_sidebar.tpl</file>
    </content>
  </contents>
  <layouts>
    <layout key="default">
      <label>Default</label>
      <file>@JarvesDemoThemeBundle/layout_default.tpl</file>
    </layout>
  </layouts>
</theme>';
        $theme = new Theme($xml, $this->getJarves());
        $theme->setId('jarvesDemoTheme');
        $theme->setLabel('Jarves cms Demo Theme');
        $content = new ThemeContent(null, $this->getJarves());
        $content->setFile('@JarvesDemoThemeBundle/content_default.tpl');
        $content->setLabel('Default');
        $content2 = new ThemeContent(null, $this->getJarves());
        $content2->setFile('@JarvesDemoThemeBundle/content_sidebar.tpl');
        $content2->setLabel('Sidebar Item');
        $theme->setContents(array($content, $content2));
        $layout = new ThemeLayout(null, $this->getJarves());
        $layout->setFile('@JarvesDemoThemeBundle/layout_default.tpl');
        $layout->setLabel('Default');
        $layout->setKey('default');
        $theme->setLayouts(array($layout));
        $this->assertEquals($xml, $theme->toXml());
        $reverse = new Theme($xml, $this->getJarves());
        $this->assertEquals('jarvesDemoTheme', $reverse->getId());
        $this->assertEquals('Jarves cms Demo Theme', $reverse->getLabel());
        $this->assertEquals('Default', $reverse->getContents()[0]->getLabel());
        $this->assertEquals('@JarvesDemoThemeBundle/content_default.tpl', $reverse->getContents()[0]->getFile());
        $this->assertEquals('Default', $reverse->getLayouts()[0]->getLabel());
        $this->assertEquals('@JarvesDemoThemeBundle/layout_default.tpl', $reverse->getLayouts()[0]->getFile());
        $this->assertEquals($xml, $reverse->toXml());
    }