/** * @param \Sonata\PageBundle\CmsManager\CmsManagerInterface $manager * @param \Sonata\PageBundle\Model\BlockInterface $block * @param \Sonata\PageBundle\Model\PageInterface $page * @param null|\Symfony\Component\HttpFoundation\Response $response * @return null|string|\Symfony\Component\HttpFoundation\Response */ public function execute(CmsManagerInterface $manager, BlockInterface $block, PageInterface $page, Response $response = null) { $settings = array_merge($this->getDefaultSettings(), $block->getSettings()); $response = $this->renderResponse('SonataPageBundle:Block:block_container.html.twig', array('container' => $block, 'manager' => $manager, 'page' => $page, 'settings' => $settings), $response); $response->setContent(Mustache::replace($settings['layout'], array('CONTENT' => $response->getContent()))); return $response; }
/** * @throws \Exception * @param \Sonata\PageBundle\CmsManager\CmsManagerInterface $manager * @param \Sonata\PageBundle\Model\BlockInterface $block * @param \Sonata\PageBundle\Model\PageInterface $page * @param null|\Symfony\Component\HttpFoundation\Response $response * @return string */ public function execute(CmsManagerInterface $manager, BlockInterface $block, PageInterface $page, Response $response = null) { $parameters = (array) json_decode($block->getSetting('parameters'), true); $parameters = array_merge($parameters, array('_block' => $block, '_page' => $page)); $settings = array_merge($this->getDefaultSettings(), (array) $block->getSettings()); try { $actionContent = $this->kernel->render($settings['action'], $parameters); } catch (\Exception $e) { throw $e; } $content = Mustache::replace($block->getSetting('layout'), array('CONTENT' => $actionContent)); return $this->renderResponse('SonataPageBundle:Block:block_core_action.html.twig', array('content' => $content, 'block' => $block, 'page' => $page), $response); }
/** * @param \Sonata\PageBundle\Model\BlockInterface $block * @param \Sonata\PageBundle\Model\PageInterface $page * @param null|\Symfony\Component\HttpFoundation\Response $response * @return string */ public function execute(CmsManagerInterface $manager, BlockInterface $block, PageInterface $page, Response $response = null) { // merge settings $settings = array_merge($this->getDefaultSettings(), $block->getSettings()); $feeds = false; if ($settings['url']) { $options = array('http' => array('user_agent' => 'Sonata/RSS Reader', 'timeout' => 2)); // retrieve contents with a specific stream context to avoid php errors $content = @file_get_contents($settings['url'], false, stream_context_create($options)); if ($content) { // generate a simple xml element try { $feeds = new \SimpleXMLElement($content); $feeds = $feeds->channel->item; } catch (\Exception $e) { // silently fail error } } } return $this->renderResponse('SonataPageBundle:Block:block_core_rss.html.twig', array('feeds' => $feeds, 'block' => $block, 'settings' => $settings), $response); }
/** * Add children * * @param \Sonata\PageBundle\Model\BlockInterface $child */ public function addChildren(BlockInterface $child) { $this->children[] = $child; $child->setParent($this); $child->setPage($this->getPage()); }
/** * @throws \RuntimeException * @param \Sonata\PageBundle\Model\BlockInterface $block * @return array|bool */ public function getCacheService(BlockInterface $block) { if (!$this->hasCacheService($block->getType())) { throw new \RuntimeException(sprintf('The block service `%s` referenced in the block `%s` does not exists', $block->getType(), $block->getId())); } return $this->cacheServices[$block->getType()]; }
/** * @param \Sonata\PageBundle\CmsManager\CmsManagerInterface $manager * @param \Sonata\PageBundle\Model\BlockInterface $block * @return void */ public function load(CmsManagerInterface $manager, BlockInterface $block) { if (is_numeric($block->getSetting('pageId'))) { $block->setSetting('pageId', $manager->getPage($block->getSetting('pageId'))); } }
/** * @param \Sonata\PageBundle\Model\BlockInterface $block * @return array */ public function createBlocks(BlockInterface $block) { $content = array(); $content['id'] = $block->getId(); $content['enabled'] = $block->getEnabled(); $content['position'] = $block->getPosition(); $content['settings'] = $block->getSettings(); $content['type'] = $block->getType(); $content['created_at'] = $block->getCreatedAt()->format('U'); $content['updated_at'] = $block->getUpdatedAt()->format('U'); $content['blocks'] = array(); foreach ($block->getChildren() as $child) { $content['blocks'][] = $this->createBlocks($child); } return $content; }
/** * @param \Sonata\AdminBundle\Validator\ErrorElement $errorElement * @param \Sonata\PageBundle\Model\BlockInterface $block * @return */ public function validateBlock(ErrorElement $errorElement, BlockInterface $block) { if (!$block->getId() && !$block->getType()) { return; } $service = $this->getBlockService($block); $service->validateBlock($this, $errorElement, $block); }
/** * Returns the cache keys for the block * * @param \Sonata\PageBundle\CmsManager\CmsManagerInterface $manager * @param \Sonata\PageBundle\Model\BlockInterface $block * @return \Sonata\PageBundle\Cache\CacheElement */ public function getCacheElement(CmsManagerInterface $manager, BlockInterface $block) { $baseCacheKeys = array('manager' => $manager->getCode(), 'block_id' => $block->getId(), 'page_id' => $block->getPage()->getId(), 'updated_at' => $block->getUpdatedAt()->format('U')); return new CacheElement($baseCacheKeys, $block->getTtl()); }
public function preUpdate(BlockInterface $block) { $block->setSetting('mediaId', is_object($block->getSetting('mediaId')) ? $block->getSetting('mediaId')->getId() : null); }
/** * @param CmsManagerInterface $manager * @param \Sonata\PageBundle\Model\BlockInterface $block * @param \Sonata\PageBundle\Model\PageInterface $page * @param null|\Symfony\Component\HttpFoundation\Response $response * @return string */ public function execute(CmsManagerInterface $manager, BlockInterface $block, PageInterface $page, Response $response = null) { $settings = array_merge($this->getDefaultSettings(), $block->getSettings()); return $this->renderResponse('SonataPageBundle:Block:block_core_text.html.twig', array('block' => $block, 'settings' => $settings), $response); }