Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Fetching contributors…

Cannot retrieve contributors at this time

106 lines (89 sloc) 3.142 kb
<?php
namespace Symfony\Cmf\Bundle\BlockBundle\Block;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Bundle\FrameworkBundle\Templating\EngineInterface;
use Sonata\BlockBundle\Block\BlockServiceInterface;
use Sonata\AdminBundle\Form\FormMapper;
use Sonata\BlockBundle\Model\BlockInterface;
use Sonata\AdminBundle\Validator\ErrorElement;
use Sonata\BlockBundle\Block\BaseBlockService;
use Sonata\BlockBundle\Block\BlockRendererInterface;
class ContainerBlockService extends BaseBlockService implements BlockServiceInterface
{
protected $blockRenderer;
protected $template = 'SymfonyCmfBlockBundle:Block:block_container.html.twig';
/**
* @param string $name
* @param \Symfony\Bundle\FrameworkBundle\Templating\EngineInterface $templating
* @param \Sonata\BlockBundle\Block\BlockRendererInterface $blockRenderer
* @param string|null $template
*/
public function __construct($name, EngineInterface $templating, BlockRendererInterface $blockRenderer, $template = null)
{
parent::__construct($name, $templating);
$this->blockRenderer = $blockRenderer;
if ($template) {
$this->template = $template;
}
}
/**
* {@inheritdoc}
*/
public function buildEditForm(FormMapper $form, BlockInterface $block)
{
throw new \RuntimeException('Not used at the moment, editing using a frontend or backend UI could be changed here');
}
/**
* {@inheritdoc}
*/
public function validateBlock(ErrorElement $errorElement, BlockInterface $block)
{
throw new \RuntimeException('Not used at the moment, validation for editing using a frontend or backend UI could be changed here');
}
/**
* @return string
*/
protected function getTemplate()
{
return $this->template;
}
/**
* @param BlockInterface $block
* @param null|Response $response
*
* @return Response
*/
public function execute(BlockInterface $block, Response $response = null)
{
if (!$response) {
$response = new Response();
}
if ($block->getEnabled()) {
// merge settings
$settings = is_array($block->getSettings()) ? array_merge($this->getDefaultSettings(), $block->getSettings()) : $this->getDefaultSettings();
$childBlocks = array();
foreach ($block->getChildren()->getValues() as $childBlock) {
$childBlocks[] = $this->blockRenderer->render($childBlock)->getContent();
}
return $this->renderResponse($this->getTemplate(), array(
'block' => $block,
'childBlocks' => $childBlocks,
'settings' => $settings
), $response);
}
return $response;
}
/**
* Returns the default settings link to the service
*
* @return array
*/
public function getDefaultSettings()
{
return array(
'divisibleBy' => false,
'divisibleClass' => '',
'childClass' => '',
);
}
}
Jump to Line
Something went wrong with that request. Please try again.