protected function setUp()
 {
     parent::setUp();
     $configurationHandler = $this->initConfigurationHandler();
     BlockFactory::boot($configurationHandler);
     $this->blockManager = new BlockManagerAdd($this->serializer, $this->optionsResolver);
 }
 public function testAllBlocksCreated()
 {
     $blocks = BlockFactory::createAllBlocks();
     $this->assertCount(2, $blocks);
     $this->assertEquals(array("Link" => 'RedKiteCms\\Block\\Link\\Core\\LinkBlock', "Text" => 'RedKiteCms\\Block\\Text\\Core\\TextBlock'), BlockFactory::getAvailableBlocks());
     $this->assertInstanceOf('\\RedKiteCms\\Block\\Link\\Core\\LinkBlock', $blocks[0]);
     $this->assertInstanceOf('\\RedKiteCms\\Block\\Text\\Core\\TextBlock', $blocks[1]);
 }
 private function addBlock($dir, array $options, $blockName)
 {
     $filename = sprintf('%s/blocks/%s.json', $dir, $blockName);
     $block = BlockFactory::createBlock($options["type"]);
     $block->setName($blockName);
     $block->setSlotName($options["slot"]);
     $blockClass = get_class($block);
     $encodedBlock = $this->serializer->serialize($block, 'json');
     $event = Dispatcher::dispatch(BlockEvents::BLOCK_ADDING, new BlockAddingEvent($this->serializer, $filename, $encodedBlock, $blockClass));
     $blockContent = $event->getFileContent();
     FilesystemTools::writeFile($filename, $blockContent);
     Dispatcher::dispatch(BlockEvents::BLOCK_ADDED, new BlockAddedEvent($this->serializer, $filename, $encodedBlock, $blockClass));
     return $blockContent;
 }
 /**
  * De-serializes a block
  *
  * @param \JMS\Serializer\Serializer $serializer
  * @param $json
  *
  * @return \RedKiteCms\Content\Block\BaseBlock
  */
 public static function toBlock(Serializer $serializer, $json)
 {
     if (empty($json)) {
         return null;
     }
     $contentArray = json_decode($json, true);
     if (!array_key_exists("type", $contentArray)) {
         return null;
     }
     $className = BlockFactory::getBlockClass($contentArray["type"]);
     if (!class_exists($className)) {
         return null;
     }
     return $serializer->deserialize($json, $className, 'json');
 }
 private function doParseChildren(array $children)
 {
     $parsedChildren = array();
     foreach ($children as $child) {
         if (!array_key_exists("type", $child)) {
             // @codeCoverageIgnoreStart
             continue;
             // @codeCoverageIgnoreEnd
         }
         $block = BlockFactory::createBlock($child["type"]);
         $encodedBlock = $this->serializer->serialize($block, 'json');
         $updatedBlock = JsonTools::join($encodedBlock, $child);
         $block = $this->serializer->deserialize(json_encode($updatedBlock), get_class($block), 'json');
         $block->updateSource();
         $children = json_decode($this->serializer->serialize($block, 'json'), true);
         if (array_key_exists("children", $children)) {
             $children["children"] = $this->doParseChildren($children["children"]);
         }
         $parsedChildren[] = $children;
     }
     return $parsedChildren;
 }
 private function boot()
 {
     BlockFactory::boot($this->app["red_kite_cms.configuration_handler"]);
     Dispatcher::setDispatcher($this->app["dispatcher"]);
     DataLogger::init($this->app["monolog"]);
     Translator::setTranslator($this->app["translator"]);
     $this->app["red_kite_cms.plugin_manager"]->boot();
     $theme = $this->app["red_kite_cms.plugin_manager"]->getActiveTheme();
     $this->app["red_kite_cms.theme"]->boot($theme);
     $this->app["red_kite_cms.theme_generator"]->boot($theme);
     $this->app["red_kite_cms.slots_generator"]->boot($theme);
     $this->app["red_kite_cms.theme_aligner"]->boot($theme);
     $siteIncompleteFile = $this->app["red_kite_cms.root_dir"] . '/app/data/' . $this->siteName . '/incomplete.json';
     if (file_exists($siteIncompleteFile)) {
         $this->createWebsitePages($theme);
         unlink($siteIncompleteFile);
     }
     $this->app["dispatcher"]->dispatch(CmsEvents::CMS_BOOTING, new CmsBootingEvent($this->app["red_kite_cms.configuration_handler"]));
     $this->app["red_kite_cms.template_assets"]->boot();
     $this->app["red_kite_cms.assetic"]->addFilter('cssrewrite', new CssRewriteFilter());
 }
 /**
  * Renders the slots
  * @param \RedKiteCms\FilesystemEntity\Page $page
  *
  * @return array
  */
 protected function renderSlots(Page $page)
 {
     $templateRenderer = $this->options['page_renderer'];
     // We need to render all blocks to avoid problems when a kind ok block is
     // not present on a page
     $availableBlocks = array();
     $blocks = BlockFactory::createAllBlocks();
     foreach ($blocks as $block) {
         if ($block->isInternal()) {
             continue;
         }
         $availableBlocks[$block->getType()] = JsonTools::toJson($this->options["serializer"], $block);
     }
     $templateRenderer->render($page, array('available_blocks' => $availableBlocks));
     $slots = $templateRenderer->getSlots();
     $cmsBlocks = $templateRenderer->renderCmsBlocks($blocks, $this->options["username"], array('available_blocks' => $availableBlocks));
     return array('slots' => $slots, 'cms_blocks' => $cmsBlocks, 'available_blocks' => $availableBlocks);
 }
 /**
  * Renders a block from a encoded json content
  * @param $encodedBlock
  *
  * @return string
  */
 public function renderBlock($encodedBlock)
 {
     $values = json_decode($encodedBlock, true);
     if (!array_key_exists("type", $values) || null === $values["type"]) {
         return "";
     }
     $block = $this->serializer->deserialize($encodedBlock, BlockFactory::getBlockClass($values["type"]), 'json');
     $blockTemplate = $this->fetchTemplateBlock($block);
     $content = $this->templating->render($blockTemplate, array('block' => $block));
     // Looks for images
     $this->updateMediaFiles('src', $content);
     // Looks for files
     $this->updateMediaFiles('href', $content);
     return $content;
 }