/**
  * Creates the slot managers from the current template slot class
  *
  * @return null|boolean
  */
 protected function setUpSlotManagers()
 {
     if (null === $this->themeSlots || null === $this->template) {
         return;
     }
     $this->slotManagers = array();
     $templateSlots = $this->template->getSlots();
     $themeSlots = $this->themeSlots->getSlots();
     foreach ($themeSlots as $slotName => $slot) {
         // slots passes only when they are repeated or belongs the current template
         if ($slot->getRepeated() == 'page' && !in_array($slotName, $templateSlots)) {
             continue;
         }
         $this->slotManagers[$slotName] = $this->createSlotManager($slot);
     }
     if (null === $this->pageBlocks) {
         return;
     }
     // Looks for included blocks' slots
     $includedSlots = array_diff(array_keys($this->pageBlocks->getBlocks()), array_keys($themeSlots));
     foreach ($includedSlots as $slotName) {
         if ($slotName != "") {
             $slot = new Slot($slotName);
             $this->slotManagers[$slotName] = $this->createSlotManager($slot);
         }
     }
 }
 /**
  * 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;
 }