Skip to content

Commit

Permalink
Always use service id as block id
Browse files Browse the repository at this point in the history
  • Loading branch information
core23 committed Jun 17, 2016
1 parent 0e9c1f9 commit 265f956
Show file tree
Hide file tree
Showing 11 changed files with 80 additions and 58 deletions.
13 changes: 13 additions & 0 deletions Block/AbstractBlockService.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,19 @@
*/
abstract class AbstractBlockService implements BlockServiceInterface
{
/**
* @var string
*/
protected $name;

/**
* @param string $name
*/
public function __construct($name)
{
$this->name = $name;
}

/**
* {@inheritdoc}
*/
Expand Down
8 changes: 2 additions & 6 deletions Block/BaseBlockService.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,6 @@
*/
abstract class BaseBlockService extends AbstractBlockService implements BlockAdminServiceInterface
{
/**
* @var string
*/
protected $name;

/**
* @var EngineInterface
*/
Expand All @@ -42,7 +37,8 @@ abstract class BaseBlockService extends AbstractBlockService implements BlockAdm
*/
public function __construct($name, EngineInterface $templating)
{
$this->name = $name;
parent::__construct($name);

$this->templating = $templating;
}

Expand Down
14 changes: 12 additions & 2 deletions DependencyInjection/Compiler/TweakCompilerPass.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,22 @@ public function process(ContainerBuilder $container)

$parameters = $container->getParameter('sonata_block.blocks');

foreach ($container->findTaggedServiceIds('sonata.block') as $id => $attributes) {
foreach ($container->findTaggedServiceIds('sonata.block') as $id => $tags) {
foreach ($tags as $attributes) {
$definition = $container->getDefinition($id);

$arguments = $definition->getArguments();

if (strlen($arguments[0]) == 0) {
$definition->replaceArgument(0, $id);
}
}

$manager->addMethodCall('add', array($id, $id, isset($parameters[$id]) ? $parameters[$id]['contexts'] : array()));
}

$services = array();
foreach ($container->findTaggedServiceIds('sonata.block.loader') as $id => $attributes) {
foreach ($container->findTaggedServiceIds('sonata.block.loader') as $id => $tags) {
$services[] = new Reference($id);
}

Expand Down
12 changes: 6 additions & 6 deletions Resources/config/block.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,34 +11,34 @@
<services>
<service id="sonata.block.service.container" class="%sonata.block.service.container.class%">
<tag name="sonata.block"/>
<argument>sonata.block.container</argument>
<argument/>
<argument type="service" id="templating"/>
</service>
<service id="sonata.block.service.empty" class="%sonata.block.service.empty.class%">
<tag name="sonata.block"/>
<argument>sonata.block.empty</argument>
<argument/>
<argument type="service" id="templating"/>
</service>
<service id="sonata.block.service.text" class="%sonata.block.service.text.class%">
<tag name="sonata.block"/>
<argument>sonata.block.text</argument>
<argument/>
<argument type="service" id="templating"/>
</service>
<service id="sonata.block.service.rss" class="%sonata.block.service.rss.class%">
<tag name="sonata.block"/>
<argument>sonata.block.rss</argument>
<argument/>
<argument type="service" id="templating"/>
</service>
<service id="sonata.block.service.menu" class="%sonata.block.service.menu.class%">
<tag name="sonata.block"/>
<argument>sonata.block.menu</argument>
<argument/>
<argument type="service" id="templating"/>
<argument type="service" id="knp_menu.menu_provider"/>
<argument type="collection"/>
</service>
<service id="sonata.block.service.template" class="%sonata.block.service.template.class%">
<tag name="sonata.block"/>
<argument>sonata.block.template</argument>
<argument/>
<argument type="service" id="templating"/>
</service>
</services>
Expand Down
2 changes: 1 addition & 1 deletion Resources/doc/reference/your_first_block.rst
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ We are almost done! Now, just declare the block as a service:
<service id="sonata.block.service.rss" class="Sonata\BlockBundle\Block\Service\RssBlockService">
<tag name="sonata.block" />
<argument>sonata.block.service.rss</argument>
<argument/>
<argument type="service" id="templating" />
</service>
Expand Down
20 changes: 10 additions & 10 deletions Resources/translations/SonataBlockBundle.de.xliff
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,24 @@
<xliff xmlns="urn:oasis:names:tc:xliff:document:1.2" version="1.2">
<file source-language="en" target-language="de" datatype="plaintext" original="SonataBlockBundle.en.xliff">
<body>
<trans-unit id="sonata.block.container">
<source>sonata.block.container</source>
<trans-unit id="sonata.block.service.container">
<source>sonata.block.service.container</source>
<target>Container</target>
</trans-unit>
<trans-unit id="sonata.block.text">
<source>sonata.block.text</source>
<trans-unit id="sonata.block.service.text">
<source>sonata.block.service.text</source>
<target>Einfacher Text</target>
</trans-unit>
<trans-unit id="sonata.block.rss">
<source>sonata.block.rss</source>
<trans-unit id="sonata.block.service.rss">
<source>sonata.block.service.rss</source>
<target>RSS Feed</target>
</trans-unit>
<trans-unit id="sonata.block.menu">
<source>sonata.block.menu</source>
<trans-unit id="sonata.block.service.menu">
<source>sonata.block.service.menu</source>
<target>Menü</target>
</trans-unit>
<trans-unit id="sonata.block.template">
<source>sonata.block.template</source>
<trans-unit id="sonata.block.service.template">
<source>sonata.block.service.template</source>
<target>Template</target>
</trans-unit>
</body>
Expand Down
20 changes: 10 additions & 10 deletions Resources/translations/SonataBlockBundle.en.xliff
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,24 @@
<xliff xmlns="urn:oasis:names:tc:xliff:document:1.2" version="1.2">
<file source-language="en" datatype="plaintext" original="file.ext">
<body>
<trans-unit id="sonata.block.container">
<source>sonata.block.container</source>
<trans-unit id="sonata.block.service.container">
<source>sonata.block.service.container</source>
<target>Container</target>
</trans-unit>
<trans-unit id="sonata.block.text">
<source>sonata.block.text</source>
<trans-unit id="sonata.block.service.text">
<source>sonata.block.service.text</source>
<target>Simple text</target>
</trans-unit>
<trans-unit id="sonata.block.rss">
<source>sonata.block.rss</source>
<trans-unit id="sonata.block.service.rss">
<source>sonata.block.service.rss</source>
<target>RSS feed</target>
</trans-unit>
<trans-unit id="sonata.block.menu">
<source>sonata.block.menu</source>
<trans-unit id="sonata.block.service.menu">
<source>sonata.block.service.menu</source>
<target>Menu</target>
</trans-unit>
<trans-unit id="sonata.block.template">
<source>sonata.block.template</source>
<trans-unit id="sonata.block.service.template">
<source>sonata.block.service.template</source>
<target>Template</target>
</trans-unit>
</body>
Expand Down
20 changes: 10 additions & 10 deletions Resources/translations/SonataBlockBundle.fr.xliff
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,24 @@
<xliff xmlns="urn:oasis:names:tc:xliff:document:1.2" version="1.2">
<file source-language="en" target-language="fr" datatype="plaintext" original="SonataBlockBundle.en.xliff">
<body>
<trans-unit id="sonata.block.container">
<source>sonata.block.container</source>
<trans-unit id="sonata.block.service.container">
<source>sonata.block.service.container</source>
<target>Conteneur</target>
</trans-unit>
<trans-unit id="sonata.block.text">
<source>sonata.block.text</source>
<trans-unit id="sonata.block.service.text">
<source>sonata.block.service.text</source>
<target>Texte</target>
</trans-unit>
<trans-unit id="sonata.block.rss">
<source>sonata.block.rss</source>
<trans-unit id="sonata.block.service.rss">
<source>sonata.block.service.rss</source>
<target>Flux RSS</target>
</trans-unit>
<trans-unit id="sonata.block.menu">
<source>sonata.block.menu</source>
<trans-unit id="sonata.block.service.menu">
<source>sonata.block.service.menu</source>
<target>Menu</target>
</trans-unit>
<trans-unit id="sonata.block.template">
<source>sonata.block.template</source>
<trans-unit id="sonata.block.service.template">
<source>sonata.block.service.template</source>
<target>Vue Partielle</target>
</trans-unit>
</body>
Expand Down
20 changes: 10 additions & 10 deletions Resources/translations/SonataBlockBundle.hu.xliff
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,24 @@
<xliff xmlns="urn:oasis:names:tc:xliff:document:1.2" version="1.2">
<file source-language="en" target-language="hu" datatype="plaintext" original="SonataBlockBundle.en.xliff">
<body>
<trans-unit id="sonata.block.container">
<source>sonata.block.container</source>
<trans-unit id="sonata.block.service.container">
<source>sonata.block.service.container</source>
<target>Konténer</target>
</trans-unit>
<trans-unit id="sonata.block.text">
<source>sonata.block.text</source>
<trans-unit id="sonata.block.service.text">
<source>sonata.block.service.text</source>
<target>Szöveg</target>
</trans-unit>
<trans-unit id="sonata.block.rss">
<source>sonata.block.rss</source>
<trans-unit id="sonata.block.service.rss">
<source>sonata.block.service.rss</source>
<target>RSS hírfolyam</target>
</trans-unit>
<trans-unit id="sonata.block.menu">
<source>sonata.block.menu</source>
<trans-unit id="sonata.block.service.menu">
<source>sonata.block.service.menu</source>
<target>Menü</target>
</trans-unit>
<trans-unit id="sonata.block.template">
<source>sonata.block.template</source>
<trans-unit id="sonata.block.service.template">
<source>sonata.block.service.template</source>
<target>Sablon</target>
</trans-unit>
</body>
Expand Down
6 changes: 3 additions & 3 deletions Tests/Block/BlockContextManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class BlockContextManagerTest extends \PHPUnit_Framework_TestCase
{
public function testGetWithValidData()
{
$service = $this->getMock('Sonata\BlockBundle\Block\AbstractBlockService');
$service = $this->getMockBuilder('Sonata\BlockBundle\Block\AbstractBlockService')->disableOriginalConstructor()->getMock();

$service->expects($this->once())->method('configureSettings');

Expand Down Expand Up @@ -47,7 +47,7 @@ public function testGetWithValidData()

public function testGetWithSettings()
{
$service = $this->getMock('Sonata\BlockBundle\Block\AbstractBlockService');
$service = $this->getMockBuilder('Sonata\BlockBundle\Block\AbstractBlockService')->disableOriginalConstructor()->getMock();
$service->expects($this->once())->method('configureSettings');

$blockLoader = $this->getMock('Sonata\BlockBundle\Block\BlockLoaderInterface');
Expand Down Expand Up @@ -88,7 +88,7 @@ public function testWithInvalidSettings()
$logger = $this->getMock('Psr\Log\LoggerInterface');
$logger->expects($this->exactly(1))->method('error');

$service = $this->getMock('Sonata\BlockBundle\Block\AbstractBlockService');
$service = $this->getMockBuilder('Sonata\BlockBundle\Block\AbstractBlockService')->disableOriginalConstructor()->getMock();
$service->expects($this->exactly(2))->method('configureSettings');

$blockLoader = $this->getMock('Sonata\BlockBundle\Block\BlockLoaderInterface');
Expand Down
3 changes: 3 additions & 0 deletions UPGRADE-4.0.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
UPGRADE FROM 3.X to 4.0
=======================

## Block id
If you have created a custom `AbstractBlockService` you must now implement the new constructor, because all blocks use the service id as the block id now. Because of that, the translation keys for the block ids have changed from `sonata.block.$NAME` to `sonata.block.service.$NAME`.

0 comments on commit 265f956

Please sign in to comment.