Skip to content

Commit

Permalink
Always use service id as block id (#344)
Browse files Browse the repository at this point in the history
  • Loading branch information
core23 authored and OskarStark committed Dec 13, 2016
1 parent 423705f commit 150d8d5
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 3 deletions.
19 changes: 17 additions & 2 deletions DependencyInjection/Compiler/TweakCompilerPass.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,27 @@ 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();

// Replace empty block id with service id
if (strlen($arguments[0]) == 0) {

This comment has been minimized.

Copy link
@wodka

wodka Apr 14, 2017

Contributor

$arguments can also be an empty array - this will create a notice then (as in #374)

This comment has been minimized.

Copy link
@core23

core23 Apr 14, 2017

Author Member

Can you provide a PR with a fix @wodka ?

This comment has been minimized.

Copy link
@wodka

wodka Apr 14, 2017

Contributor

of course :) - added in #378

$definition->replaceArgument(0, $id);
} elseif ($id != $arguments[0]) {
// NEXT_MAJOR: Remove deprecation notice
@trigger_error(
'Using different service id and block id is deprecated since 3.x and will be removed in 4.0.',
E_USER_DEPRECATED
);
}

$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
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: 20 additions & 0 deletions UPGRADE-3.x.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,26 @@
UPGRADE 3.x
===========

Injecting the block id into a service is deprecated and will be automatically set.

Instead, provide an empty argument:

## Before
```
<service id="acme.block.service" class="Acme\BlockBundle\AcmeBlockService">
<tag name="sonata.block"/>
<argument>acme.block.service</argument>
</service>
```

## After
```
<service id="acme.block.service" class="Acme\BlockBundle\AcmeBlockService">
<tag name="sonata.block"/>
<argument/>
</service>
```

UPGRADE FROM 3.1 to 3.2
=======================

Expand Down

0 comments on commit 150d8d5

Please sign in to comment.