From d63f79f1df35820daa2537c8f56c13baac44b848 Mon Sep 17 00:00:00 2001 From: core23 Date: Fri, 10 Jun 2016 13:11:41 +0200 Subject: [PATCH] Always use service id as block id --- Block/AbstractBlockService.php | 12 +++++++++++ Block/BaseBlockService.php | 8 ++------ .../Compiler/TweakCompilerPass.php | 12 +++++++++-- Resources/config/block.xml | 12 +++++------ Resources/doc/reference/your_first_block.rst | 2 +- .../translations/SonataBlockBundle.de.xliff | 20 +++++++++---------- .../translations/SonataBlockBundle.en.xliff | 20 +++++++++---------- .../translations/SonataBlockBundle.fr.xliff | 20 +++++++++---------- .../translations/SonataBlockBundle.hu.xliff | 20 +++++++++---------- Tests/Block/BlockContextManagerTest.php | 6 +++--- UPGRADE-4.0.md | 4 ++++ 11 files changed, 78 insertions(+), 58 deletions(-) diff --git a/Block/AbstractBlockService.php b/Block/AbstractBlockService.php index d6f1d313c..f295a4b53 100644 --- a/Block/AbstractBlockService.php +++ b/Block/AbstractBlockService.php @@ -18,4 +18,16 @@ */ abstract class AbstractBlockService implements BlockServiceInterface { + /** + * @var string + */ + protected $name; + + /** + * @param string $name + */ + public function __construct($name) + { + $this->name = $name; + } } diff --git a/Block/BaseBlockService.php b/Block/BaseBlockService.php index 6d1da1db1..4e38774a7 100644 --- a/Block/BaseBlockService.php +++ b/Block/BaseBlockService.php @@ -26,11 +26,6 @@ */ abstract class BaseBlockService extends AbstractBlockService implements BlockAdminServiceInterface { - /** - * @var string - */ - protected $name; - /** * @var EngineInterface */ @@ -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; } diff --git a/DependencyInjection/Compiler/TweakCompilerPass.php b/DependencyInjection/Compiler/TweakCompilerPass.php index a9a0f442a..67569886e 100644 --- a/DependencyInjection/Compiler/TweakCompilerPass.php +++ b/DependencyInjection/Compiler/TweakCompilerPass.php @@ -31,12 +31,20 @@ 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) { + $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); } diff --git a/Resources/config/block.xml b/Resources/config/block.xml index c08356e5a..a6c004874 100644 --- a/Resources/config/block.xml +++ b/Resources/config/block.xml @@ -11,34 +11,34 @@ - sonata.block.container + - sonata.block.empty + - sonata.block.text + - sonata.block.rss + - sonata.block.menu + - sonata.block.template + diff --git a/Resources/doc/reference/your_first_block.rst b/Resources/doc/reference/your_first_block.rst index 3ef530255..a2dd47527 100644 --- a/Resources/doc/reference/your_first_block.rst +++ b/Resources/doc/reference/your_first_block.rst @@ -177,7 +177,7 @@ We are almost done! Now, just declare the block as a service: - sonata.block.service.rss + diff --git a/Resources/translations/SonataBlockBundle.de.xliff b/Resources/translations/SonataBlockBundle.de.xliff index 63b312a7e..5da8eba27 100644 --- a/Resources/translations/SonataBlockBundle.de.xliff +++ b/Resources/translations/SonataBlockBundle.de.xliff @@ -2,24 +2,24 @@ - - sonata.block.container + + sonata.block.service.container Container - - sonata.block.text + + sonata.block.service.text Einfacher Text - - sonata.block.rss + + sonata.block.service.rss RSS Feed - - sonata.block.menu + + sonata.block.service.menu Menü - - sonata.block.template + + sonata.block.service.template Template diff --git a/Resources/translations/SonataBlockBundle.en.xliff b/Resources/translations/SonataBlockBundle.en.xliff index 305567ee5..37df3b85a 100644 --- a/Resources/translations/SonataBlockBundle.en.xliff +++ b/Resources/translations/SonataBlockBundle.en.xliff @@ -2,24 +2,24 @@ - - sonata.block.container + + sonata.block.service.container Container - - sonata.block.text + + sonata.block.service.text Simple text - - sonata.block.rss + + sonata.block.service.rss RSS feed - - sonata.block.menu + + sonata.block.service.menu Menu - - sonata.block.template + + sonata.block.service.template Template diff --git a/Resources/translations/SonataBlockBundle.fr.xliff b/Resources/translations/SonataBlockBundle.fr.xliff index 25497a4ab..d8b395cbd 100644 --- a/Resources/translations/SonataBlockBundle.fr.xliff +++ b/Resources/translations/SonataBlockBundle.fr.xliff @@ -2,24 +2,24 @@ - - sonata.block.container + + sonata.block.service.container Conteneur - - sonata.block.text + + sonata.block.service.text Texte - - sonata.block.rss + + sonata.block.service.rss Flux RSS - - sonata.block.menu + + sonata.block.service.menu Menu - - sonata.block.template + + sonata.block.service.template Vue Partielle diff --git a/Resources/translations/SonataBlockBundle.hu.xliff b/Resources/translations/SonataBlockBundle.hu.xliff index fac7de51c..d0487c674 100644 --- a/Resources/translations/SonataBlockBundle.hu.xliff +++ b/Resources/translations/SonataBlockBundle.hu.xliff @@ -2,24 +2,24 @@ - - sonata.block.container + + sonata.block.service.container Konténer - - sonata.block.text + + sonata.block.service.text Szöveg - - sonata.block.rss + + sonata.block.service.rss RSS hírfolyam - - sonata.block.menu + + sonata.block.service.menu Menü - - sonata.block.template + + sonata.block.service.template Sablon diff --git a/Tests/Block/BlockContextManagerTest.php b/Tests/Block/BlockContextManagerTest.php index 92a45aae1..a03da9505 100644 --- a/Tests/Block/BlockContextManagerTest.php +++ b/Tests/Block/BlockContextManagerTest.php @@ -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'); @@ -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'); @@ -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'); diff --git a/UPGRADE-4.0.md b/UPGRADE-4.0.md index 0d421ffae..41901c548 100644 --- a/UPGRADE-4.0.md +++ b/UPGRADE-4.0.md @@ -8,3 +8,7 @@ All the deprecated code introduced on 3.x is removed on 4.0. Please read [3.x](https://github.com/sonata-project/SonataAdminBundle/tree/3.x) upgrade guides for more information. See also the [diff code](https://github.com/sonata-project/SonataAdminBundle/compare/3.x...4.0.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`.