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