Exemple #1
0
 public function showBlock($code)
 {
     $block = ServiceKernel::instance()->createService('Content.BlockService')->getBlockByCode($code);
     if (empty($block)) {
         return '';
     }
     $env = $this->container->getParameter('kernel.environment');
     if ($env == 'prod') {
         return $block['content'];
     }
     // 从data渲染生成html然后返回
     return BlockToolkit::render($block, $this->container);
 }
Exemple #2
0
 private function generateBlcokContent($metaFilePath)
 {
     $metas = file_get_contents($metaFilePath);
     $metas = json_decode($metas, true);
     if (empty($metas)) {
         throw new \RuntimeException("插件元信息文件{$metaFilePath}格式不符合JSON规范,解析失败,请检查元信息文件格式");
     }
     foreach ($metas as $code => $meta) {
         $data = array();
         foreach ($meta['items'] as $key => $item) {
             $data[$key] = $item['default'];
         }
         $block = array('templateName' => $meta['templateName'], 'data' => $data);
         $html = BlockToolkit::render($block, $this->getContainer());
         $filename = "block-" . md5($code) . '.html';
         $folder = "{$this->distDirectory}/web/install/blocks/";
         if (!file_exists($folder)) {
             mkdir($folder);
         }
         $filename = $folder . $filename;
         file_put_contents($filename, $html);
     }
 }
Exemple #3
0
 protected function replaceContent(&$block, $output)
 {
     $output->writeln('<info>替换CONTENT数据</info>');
     $newContent = BlockToolkit::render($block, $this->getContainer());
     $block['content'] = $newContent;
 }
Exemple #4
0
 public function visualEditAction(Request $request, $blockId)
 {
     $block = $this->getBlockService()->getBlock($blockId);
     if ('POST' == $request->getMethod()) {
         $data = $request->request->get('data');
         $block['data'] = $data;
         $html = BlockToolkit::render($block, $this->container);
         $block = $this->getBlockService()->updateBlock($blockId, array('data' => $data, 'content' => $html));
         $this->setFlashMessage('success', '保存成功!');
     }
     return $this->render('TopxiaAdminBundle:Block:block-visual-edit.html.twig', array('block' => $block, 'action' => 'edit'));
 }