Exemplo n.º 1
0
 /**
  * Generates the template's subsections and the full template itself
  */
 protected function generateBaseTemplate(PageTree $pageTree, ThemeInterface $theme, array $options)
 {
     $options["filter"] = array('site', 'language');
     $this->twigTemplate = sprintf("{%% extends '%s:Theme:%s.html.twig' %%}" . PHP_EOL, $theme->getThemeName(), $this->template->getTemplateName());
     $this->twigTemplate .= $this->contentSection->generateSection($pageTree, $theme, $options);
     return $this;
 }
 /**
  * Compares the slots and updates the contents according the new status
  *
  * @param \RedKiteLabs\ThemeEngineBundle\Core\Template\Template $template
  * @param array                                                   $templateSlots The template's slots
  *
  * @return null|boolean null is returned when any update is made
  *
  * @api
  */
 public function align(Template $template, array $templateSlots)
 {
     $slots = array_flip($template->getSlots());
     if (empty($templateSlots) || empty($slots)) {
         return null;
     }
     $templateName = strtolower($template->getTemplateName());
     $templateSlots = array_intersect_key($templateSlots, $slots);
     if (null === $this->languageId) {
         $languageRepository = $this->factoryRepository->createRepository('Language');
         $language = $languageRepository->mainLanguage();
         $this->languageId = $language->getId();
     }
     if (null === $this->pageId) {
         $pageRepository = $this->factoryRepository->createRepository('Page');
         $page = $pageRepository->fromTemplateName($templateName, true);
         $this->pageId = $page->getId();
     }
     $pageBlocks = $this->blockRepository->retrieveContents(array(1, $this->languageId), array(1, $this->pageId));
     $currentSlots = $this->templateSlotsToArray($templateSlots);
     $changedSlots = array();
     foreach ($pageBlocks as $pageBlock) {
         $slotName = $pageBlock->getSlotName();
         if (array_key_exists($slotName, $currentSlots)) {
             $languageId = $pageBlock->getLanguageId();
             $pageId = $pageBlock->getPageId();
             $currentRepeatedStatus = 'page';
             if ($languageId == 1 && $pageId == 1) {
                 $currentRepeatedStatus = 'site';
             }
             if ($languageId != 1 && $pageId == 1) {
                 $currentRepeatedStatus = 'language';
             }
             if ($currentRepeatedStatus != $currentSlots[$slotName]) {
                 $changedSlots[$slotName] = $currentSlots[$slotName];
             }
         }
     }
     return !empty($changedSlots) ? $this->updateSlotStatus($templateSlots, $changedSlots) : null;
 }