public function testGetBlockClass()
 {
     $blockClass = BlockFactory::getBlockClass('Foo');
     $this->assertEquals('', $blockClass);
     $blockClass = BlockFactory::getBlockClass('Link');
     $this->assertEquals('RedKiteCms\\Block\\Link\\Core\\LinkBlock', $blockClass);
 }
 /**
  * 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');
 }
 /**
  * Edits the given block
  *
  * @param string $sourceDir
  * @param array $options
  * @param string $username
  * @param array $values
  */
 public function edit($sourceDir, array $options, $username, $values)
 {
     $this->resolveOptions($options);
     $this->init($sourceDir, $options, $username);
     $this->createContributorDir($sourceDir, $options, $username);
     $filename = sprintf('%s/blocks/%s.json', $this->getDirInUse(), $options["blockname"]);
     $currentBlock = $options["baseBlock"] = JsonTools::jsonDecode(FilesystemTools::readFile($filename));
     $values = $this->parseChildren($values);
     $block = JsonTools::join($currentBlock, $values);
     $encodedBlock = json_encode($block);
     $blockClass = BlockFactory::getBlockClass($block["type"]);
     $event = Dispatcher::dispatch(BlockEvents::BLOCK_EDITING, new BlockEditingEvent($this->serializer, $filename, $encodedBlock, $blockClass));
     $blockContent = $event->getFileContent();
     FilesystemTools::writeFile($filename, $blockContent);
     Dispatcher::dispatch(BlockEvents::BLOCK_EDITED, new BlockEditedEvent($this->serializer, $filename, $encodedBlock, $blockClass));
     DataLogger::log(sprintf('Block "%s" has been edited on the "%s" slot on page "%s" for the "%s_%s" language', $options["blockname"], $options["slot"], $options["page"], $options["language"], $options["country"]));
 }
 /**
  * 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;
 }