/**
  * Returns the template to render
  * @param \RedKiteCms\Rendering\Controller\Cms\Page $page
  *
  * @return string
  */
 protected function fetchTemplate(Page $page)
 {
     $themeName = $this->configuration->theme();
     $pageAttributes = $page->getPageAttributes();
     $pageName = $pageAttributes["template"];
     return sprintf('%s/Resources/views/%s.html.twig', $themeName, $pageName);
 }
 /**
  * Synchronizes the site slots with the theme slots
  *
  * @param \RedKiteCms\FilesystemEntity\Page $page
  * @param array $pages
  */
 public function synchronize(Page $page, array $pages)
 {
     if (!$this->configurationHandler->isTheme()) {
         return;
     }
     foreach ($pages as $pageValues) {
         $tokens = explode("_", $pageValues["seo"][0]["language"]);
         $pageOptions = array('page' => $pageValues["name"], 'language' => $tokens[0], 'country' => $tokens[1]);
         $page->render($this->configurationHandler->siteDir(), $pageOptions);
         $this->saveTemplateSlots($page->getPageSlots(), $pageValues["template"]);
     }
     $this->saveTemplateSlots($page->getCommonSlots(), 'base');
 }
 private function createWebsitePages($theme)
 {
     $isTheme = $this->app["red_kite_cms.configuration_handler"]->isTheme();
     $user = null;
     if (!$isTheme) {
         $user = '******';
     }
     $language = "en_GB";
     $pages = $theme->getPages();
     if (null == $pages) {
         $this->registerTwig();
         echo $this->app["twig"]->render('RedKiteCms/Resources/views/Bootstrap/bootstrap.html.twig', array("theme_name" => $theme->getName(), "site_path" => $this->app["red_kite_cms.configuration_handler"]->siteDir()));
         exit;
     }
     $this->app["red_kite_cms.page_collection_manager"]->contributor($user);
     $theme = $this->app["red_kite_cms.theme"];
     $this->app["red_kite_cms.slots_generator"]->generate();
     foreach ($pages as $pageName => $templateName) {
         $page = array("name" => $pageName, "template" => $templateName, "seo" => array(array("permalink" => str_replace('_', '-', strtolower($language)) . "-" . $pageName, "changed_permalinks" => array(), "title" => $pageName . '-title', "description" => $pageName . '-description', "keywords" => $pageName . '-keywords', "sitemap_frequency" => 'monthly', "sitemap_priority" => '0.5', "language" => $language)));
         $this->app["red_kite_cms.page_collection_manager"]->add($theme, $page);
         $page = new Page($this->app["jms.serializer"], new OptionsResolver(), $this->app["red_kite_cms.slot_parser"]);
         $pageOptions = array('page' => $pageName, 'language' => 'en', 'country' => 'GB');
         $page->render($this->app["red_kite_cms.configuration_handler"]->siteDir(), $pageOptions, $user);
         $this->savePermalinks($page->getPageSlots());
         $this->savePermalinks($page->getCommonSlots());
         $this->app["red_kite_cms.permalink_manager"]->save();
     }
     if (!$isTheme) {
         $blockManager = new BlockManagerApprover($this->app["jms.serializer"], new OptionsResolver());
         $this->app["red_kite_cms.deployer"]->contributor('admin')->saveAllPages($blockManager, array('en_GB'));
     }
     $fileSystem = new Filesystem();
     $fileSystem->remove($this->app["red_kite_cms.configuration_handler"]->siteCacheDir());
 }
 /**
  * Generates the events based on the current page.
  *
  * RedKite CMS will generate four events:
  *
  * 1. [ Base render name ] This event is used to change a slot content for the entire site
  * 2. [ Base render name ].[ Language ] This event is used to change a slot content for the event language
  * 3. [ Base render name ].[ Page ] This event is used to change a slot content for the event page collection
  * 4. [ Base render name ].[ Language ].[ Page ] This event is used to change a slot content for the event page and
  * language
  *
  * @param $baseEventName
  * @param \RedKiteCms\FilesystemEntity\Page $page
  *
  * @return array
  */
 protected function generateEventNames($baseEventName, Page $page)
 {
     $pageName = $page->getPageName();
     $language = $page->getCurrentLanguage();
     return array($baseEventName, $baseEventName . '.' . $language, $baseEventName . '.' . $pageName, $baseEventName . '.' . $language . '.' . $pageName);
 }