/** * @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\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); }
/** * @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; }
/** * 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()); }