SonataBlockBundle: [BC BREAK] Name parameter autowiring broken
Environment
Sonata packages
$ composer show --latest 'sonata-project/*'
sonata-project/admin-bundle 3.39.0 3.43.0 The missing Symfony Admin Generator
sonata-project/block-bundle 3.13.0 3.13.0 Symfony SonataBlockBundle
sonata-project/cache 2.0.1 2.0.1 Cache library
sonata-project/core-bundle 3.11.2 3.13.7 Symfony SonataCoreBundle
sonata-project/datagrid-bundle 2.3.1 2.4.0 Symfony SonataDatagridBundle
sonata-project/doctrine-extensions 1.0.2 1.1.3 Doctrine2 behavioral extensions
sonata-project/doctrine-orm-admin-bundle 3.5.1 3.7.0 Symfony Sonata / Integrate Doctrine ORM into the SonataAdminBundle
sonata-project/easy-extends-bundle 2.5.0 2.5.0 Symfony SonataEasyExtendsBundle
sonata-project/exporter 1.9.1 2.0.0 Lightweight Exporter library
sonata-project/intl-bundle 2.5.0 2.5.0 Symfony SonataIntlBundle
Another info (same issue with a global composer update):
Updating sonata-project/block-bundle (3.12.1 => 3.13.0)
Symfony packages
$ composer show --latest 'symfony/*'
symfony/asset v4.1.4 v4.2.1 Symfony Asset Component
symfony/browser-kit v4.1.4 v4.2.1 Symfony BrowserKit Component
symfony/cache v4.2.0 v4.2.1 Symfony Cache component with PSR-6, PSR-16, and tags
symfony/config v4.2.0 v4.2.1 Symfony Config Component
symfony/console v4.1.4 v4.2.1 Symfony Console Component
symfony/contracts v1.0.0-RC1 v1.0.2 A set of abstractions extracted out of the Symfony components
symfony/css-selector v4.1.4 v4.2.1 Symfony CssSelector Component
symfony/debug v4.1.8 v4.2.1 Symfony Debug Component
symfony/debug-bundle v4.1.4 v4.2.1 Symfony DebugBundle
symfony/dependency-injection v4.2.0 v4.2.1 Symfony DependencyInjection Component
symfony/doctrine-bridge v4.1.4 v4.2.1 Symfony Doctrine Bridge
symfony/dom-crawler v4.1.4 v4.2.1 Symfony DomCrawler Component
symfony/dotenv v4.2.0 v4.2.1 Registers environment variables from a .env file
symfony/event-dispatcher v4.1.8 v4.2.1 Symfony EventDispatcher Component
symfony/expression-language v4.1.4 v4.2.1 Symfony ExpressionLanguage Component
symfony/filesystem v4.1.8 v4.2.1 Symfony Filesystem Component
symfony/finder v4.1.8 v4.2.1 Symfony Finder Component
symfony/flex v1.1.1 v1.1.8 Composer plugin for Symfony
symfony/form v4.2.0 v4.2.1 Symfony Form Component
symfony/framework-bundle v4.2.0 v4.2.1 Symfony FrameworkBundle
symfony/http-foundation v4.1.8 v4.2.1 Symfony HttpFoundation Component
symfony/http-kernel v4.2.0 v4.2.1 Symfony HttpKernel Component
symfony/inflector v4.1.8 v4.2.1 Symfony Inflector Component
symfony/intl v4.1.8 v4.2.1 A PHP replacement layer for the C intl extension that includes additional data from the ICU library.
symfony/lock v4.1.4 v4.2.1 Symfony Lock Component
symfony/monolog-bridge v4.1.4 v4.2.1 Symfony Monolog Bridge
symfony/monolog-bundle v3.3.0 v3.3.1 Symfony MonologBundle
symfony/options-resolver v4.2.0 v4.2.1 Symfony OptionsResolver Component
symfony/phpunit-bridge v4.1.4 v4.2.1 Symfony PHPUnit Bridge
symfony/polyfill-ctype v1.10.0 v1.10.0 Symfony polyfill for ctype functions
symfony/polyfill-intl-icu v1.10.0 v1.10.0 Symfony polyfill for intl's ICU-related data and classes
symfony/polyfill-mbstring v1.10.0 v1.10.0 Symfony polyfill for the Mbstring extension
symfony/polyfill-php56 v1.9.0 v1.10.0 Symfony polyfill backporting some PHP 5.6+ features to lower PHP versions
symfony/polyfill-php70 v1.9.0 v1.10.0 Symfony polyfill backporting some PHP 7.0+ features to lower PHP versions
symfony/polyfill-php72 v1.9.0 v1.10.0 Symfony polyfill backporting some PHP 7.2+ features to lower PHP versions
symfony/polyfill-util v1.9.0 v1.10.0 Symfony utilities for portability of PHP codes
symfony/process v4.1.4 v4.2.1 Symfony Process Component
symfony/property-access v4.1.8 v4.2.1 Symfony PropertyAccess Component
symfony/property-info v4.1.4 v4.2.1 Symfony Property Info Component
symfony/proxy-manager-bridge v4.1.4 v4.2.1 Symfony ProxyManager Bridge
symfony/psr-http-message-bridge v1.1.0 v1.1.0 PSR HTTP message bridge
symfony/routing v4.1.8 v4.2.1 Symfony Routing Component
symfony/security v4.1.4 v4.2.1 Symfony Security Component
symfony/security-acl v3.0.1 v3.0.1 Symfony Security Component - ACL (Access Control List)
symfony/security-bundle v4.1.4 v4.2.1 Symfony SecurityBundle
symfony/serializer v4.2.0 v4.2.1 Symfony Serializer Component
symfony/stopwatch v4.1.4 v4.2.1 Symfony Stopwatch Component
symfony/swiftmailer-bundle v3.2.3 v3.2.4 Symfony SwiftmailerBundle
symfony/templating v4.1.8 v4.2.1 Symfony Templating Component
symfony/translation v4.2.0 v4.2.1 Symfony Translation Component
symfony/twig-bridge v4.1.4 v4.2.1 Symfony Twig Bridge
symfony/twig-bundle v4.1.4 v4.2.1 Symfony TwigBundle
symfony/validator v4.1.4 v4.2.1 Symfony Validator Component
symfony/var-dumper v4.1.4 v4.2.1 Symfony mechanism for exploring and dumping PHP variables
symfony/var-exporter v4.2.0 v4.2.1 A blend of var_export() + serialize() to turn any serializable data structure to plain PHP code
symfony/web-link v4.2.1 v4.2.1 Symfony WebLink Component
symfony/web-profiler-bundle v4.1.4 v4.2.1 Symfony WebProfilerBundle
symfony/yaml v4.1.4 v4.2.1 Symfony Yaml Component
PHP version
$ php -v
PHP 7.2.12 (cli) (built: Nov 16 2018 03:17:59) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.2.0, Copyright (c) 1998-2018 Zend Technologies
Subject
The update from 3.12.1 to 3.13.0 broke the custom block service definition.
Steps to reproduce
This class sample:
namespace AppBundle\Block\Admin;
use AppBundle\Entity\User;
use Doctrine\ORM\EntityManagerInterface;
use Sonata\BlockBundle\Block\BaseBlockService;
use Sonata\BlockBundle\Block\BlockContextInterface;
use Symfony\Bundle\FrameworkBundle\Templating\EngineInterface;
use Symfony\Component\HttpFoundation\Response;
class ActiveUsersBlockService extends BaseBlockService
{
/**
* @var EntityManagerInterface
*/
private $entityManager;
public function __construct(string $name, EngineInterface $templating, EntityManagerInterface $entityManager)
{
parent::__construct($name, $templating);
$this->entityManager = $entityManager;
}
public function execute(BlockContextInterface $blockContext, ?Response $response = null): Response
{
$activeUsers = $this->entityManager->getRepository(User::class)->findActiveUsers();
return $this->renderPrivateResponse('admin/Block/block_active_users.html.twig', [
'block' => $blockContext->getBlock(),
'settings' => $blockContext->getSettings(),
'activeUsers' => $activeUsers,
], $response);
}
}
Expected results
Should not throw issue as on 3.12.
Actual results
Broke on 3.13 with this message:
Cannot autowire service "AppBundle\Block\Admin\ActiveUsersBlockService": argument "$name" of method "__construct()" is type-hinted "string", you should configure its value explicitly.
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Comments: 18 (18 by maintainers)
@core23 i think it would be better to use the class name as the default block name and overwrite it in concrete block class if need. https://github.com/sonata-project/SonataBlockBundle/blob/3.x/src/Block/Service/AbstractBlockService.php#L152
Autowiring the name was a bad idea, we should remove this