Permalink
Browse files

removed custom service for slideshows and reuse ContainerBlockService…

… instead
  • Loading branch information...
elHornair committed Mar 1, 2013
1 parent 04ee009 commit 0600ff150bfc3211519bc28d2eb5f9a638577f4a
@@ -15,16 +15,23 @@ class ContainerBlockService extends BaseBlockService implements BlockServiceInte
{
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)
+ public function __construct($name, EngineInterface $templating, BlockRendererInterface $blockRenderer, $template = null)
{
parent::__construct($name, $templating);
+
$this->blockRenderer = $blockRenderer;
+
+ if ($template) {
+ $this->template = $template;
+ }
}
/**
@@ -48,7 +55,7 @@ public function validateBlock(ErrorElement $errorElement, BlockInterface $block)
*/
protected function getTemplate()
{
- return 'SymfonyCmfBlockBundle:Block:block_container.html.twig';
+ return $this->template;
}
/**
@@ -73,6 +80,7 @@ public function execute(BlockInterface $block, Response $response = null)
}
return $this->renderResponse($this->getTemplate(), array(
+ 'block' => $block,
'childBlocks' => $childBlocks,
'settings' => $settings
), $response);
@@ -1,55 +0,0 @@
-<?php
-
-namespace Symfony\Cmf\Bundle\BlockBundle\Block;
-
-use Symfony\Component\HttpFoundation\Response;
-use Sonata\BlockBundle\Model\BlockInterface;
-use Symfony\Cmf\Bundle\BlockBundle\Block\ContainerBlockService;
-
-class SlideshowBlockService extends ContainerBlockService
-{
-
- /**
- * @return string
- */
- protected function getTemplate()
- {
- return 'SymfonyCmfBlockBundle:Block:block_slideshow.html.twig';
- }
-
- /**
- * @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()) {
- $childBlocks = array();
- foreach ($block->getChildren()->getValues() as $childBlock) {
- $expectedType = 'Symfony\Cmf\Bundle\BlockBundle\Document\SlideshowItemBlock';
- if (!$childBlock instanceof $expectedType) {
- throw new \RuntimeException(sprintf('Expected block of type %s. Received block of type %s instead.', $expectedType, get_class($childBlock)));
- }
- $childBlocks[] = $childBlock;
- }
-
- if (!empty($childBlock)) {
- return $this->renderResponse($this->getTemplate(), array(
- 'block' => $block,
- 'itemBlocks' => $childBlocks,
- 'settings' => $this->getDefaultSettings()
- ), $response);
- }
-
- }
-
- return $response;
- }
-
-}
@@ -41,11 +41,21 @@
<argument type="service" id="http_kernel" />
</service>
- <service id="symfony_cmf.block.slideshow" class="Symfony\Cmf\Bundle\BlockBundle\Block\SlideshowBlockService">
+ <!--container block service is reused for slideshows -->
+ <service id="symfony_cmf.block.slideshow" class="Symfony\Cmf\Bundle\BlockBundle\Block\ContainerBlockService">
<tag name="sonata.block" />
<argument>symfony_cmf.block.slideshow</argument>
<argument type="service" id="templating" />
<argument type="service" id="sonata.block.renderer" />
+ <argument>SymfonyCmfBlockBundle:Block:block_slideshow.html.twig</argument>
+ </service>
+
+ <!-- simple block service is reused for slideshow items -->
+ <service id="symfony_cmf.block.slideshow_item" class="Symfony\Cmf\Bundle\BlockBundle\Block\SimpleBlockService">
+ <tag name="sonata.block" />
+ <argument>symfony_cmf.block.slideshow_item</argument>
+ <argument type="service" id="templating" />
+ <argument>SymfonyCmfBlockBundle:Block:block_slideshow_item.html.twig</argument>
</service>
</services>
@@ -2,14 +2,15 @@
{% block block %}
- <h3>Block title: {{ block.title }}</h3>
-
- <div class="slideshow">
- <ul>
- {% for item in itemBlocks %}
- <li><span id="label">{{ item.label }}</span><img src="{{ item.image | imagine_filter('slideshow_image') }}" alt="{{ item.label }}" /></li>
- {% endfor %}
- </ul>
- </div>
+ {% if childBlocks %}
+ <h3>Block title: {{ block.title }}</h3>
+ <div class="slideshow">
+ <ul>
+ {% for item in childBlocks %}
+ <li>{{ item | raw }}</li>
+ {% endfor %}
+ </ul>
+ </div>
+ {% endif %}
{% endblock %}
@@ -0,0 +1,5 @@
+{% extends 'SymfonyCmfBlockBundle:Block:block_base.html.twig' %}
+
+{% block block %}
+ <span id="label">{{ block.label }}</span><img src="{{ block.image | imagine_filter('slideshow_image') }}" alt="{{ block.label }}" />
+{% endblock %}

0 comments on commit 0600ff1

Please sign in to comment.