Skip to content
This repository has been archived by the owner on Sep 16, 2021. It is now read-only.

Commit

Permalink
removed custom service for slideshows and reuse ContainerBlockService…
Browse files Browse the repository at this point in the history
… instead
  • Loading branch information
Alain Horner committed Mar 1, 2013
1 parent 04ee009 commit 0600ff1
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 67 deletions.
12 changes: 10 additions & 2 deletions Block/ContainerBlockService.php
Expand Up @@ -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;
}
}

/**
Expand All @@ -48,7 +55,7 @@ public function validateBlock(ErrorElement $errorElement, BlockInterface $block)
*/
protected function getTemplate()
{
return 'SymfonyCmfBlockBundle:Block:block_container.html.twig';
return $this->template;
}

/**
Expand All @@ -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);
Expand Down
55 changes: 0 additions & 55 deletions Block/SlideshowBlockService.php

This file was deleted.

12 changes: 11 additions & 1 deletion Resources/config/services.xml
Expand Up @@ -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>
Expand Down
19 changes: 10 additions & 9 deletions Resources/views/Block/block_slideshow.html.twig
Expand Up @@ -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 %}
5 changes: 5 additions & 0 deletions Resources/views/Block/block_slideshow_item.html.twig
@@ -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.