Sonataadminbundle: argument "$code" of method "Sonata\AdminBundle\Admin\AbstractAdmin::__construct()" has no type-hint

Created on 15 Jun 2019  路  2Comments  路  Source: sonata-project/SonataAdminBundle

Hy folks, I just upgraded my Symfony version to 4 and Sonata admin to 3 and gets below error;

Cannot autowire service "admin.app.business": argument "$code" of method "Sonata\AdminBundle\Admin\AbstractAdmin::__construct()" has no type-hint, you should configure its value explicit  
  ly.

Environment

UBUNTU 18, PHP7.2, Symfony v4.2.9

Sonata packages

sonata-project/admin-bundle              3.49.1    The missing Symfony Admin Generator
sonata-project/block-bundle              3.15.0    Symfony SonataBlockBundle
sonata-project/cache                     2.0.1     Cache library
sonata-project/core-bundle               3.17.0    Symfony SonataCoreBundle
sonata-project/datagrid-bundle           2.5.0     Symfony SonataDatagridBundle
sonata-project/doctrine-extensions       1.3.0     Doctrine2 behavioral extensions
sonata-project/doctrine-orm-admin-bundle 3.9.0     Symfony Sonata / Integrate Doctrine ORM into the SonataAdminBundle
sonata-project/easy-extends-bundle       2.5.0     Symfony SonataEasyExtendsBundle
sonata-project/exporter                  2.0.1     Lightweight Exporter library
sonata-project/user-bundle               4.4.0     Symfony SonataUserBundle

Symfony packages

friendsofsymfony/user-bundle             v2.1.2    Symfony FOSUserBundle
symfony/apache-pack                      v1.0.1    A pack for Apache support in Symfony
symfony/asset                            v4.2.9    Symfony Asset Component
symfony/browser-kit                      v4.3.1    Symfony BrowserKit Component
symfony/cache                            v4.3.1    Symfony Cache component with PSR-6, PSR-16, and tags
symfony/config                           v4.3.1    Symfony Config Component
symfony/console                          v4.2.9    Symfony Console Component
symfony/contracts                        v1.1.3    A set of abstractions extracted out of the Symfony components
symfony/css-selector                     v4.3.1    Symfony CssSelector Component
symfony/debug                            v4.3.1    Symfony Debug Component
symfony/debug-bundle                     v4.3.1    Symfony DebugBundle
symfony/debug-pack                       v1.0.7    A debug pack for Symfony projects
symfony/dependency-injection             v4.3.1    Symfony DependencyInjection Component
symfony/doctrine-bridge                  v4.2.9    Symfony Doctrine Bridge
symfony/dom-crawler                      v4.3.1    Symfony DomCrawler Component
symfony/dotenv                           v4.2.9    Registers environment variables from a .env file
symfony/event-dispatcher                 v4.2.9    Symfony EventDispatcher Component
symfony/expression-language              v4.2.9    Symfony ExpressionLanguage Component
symfony/filesystem                       v4.3.1    Symfony Filesystem Component
symfony/finder                           v4.3.1    Symfony Finder Component
symfony/flex                             v1.2.6    Composer plugin for Symfony
symfony/form                             v4.2.9    Symfony Form Component
symfony/framework-bundle                 v4.2.9    Symfony FrameworkBundle
symfony/http-client                      v4.3.1    Symfony HttpClient component
symfony/http-foundation                  v4.3.1    Symfony HttpFoundation Component
symfony/http-kernel                      v4.2.9    Symfony HttpKernel Component
symfony/inflector                        v4.3.1    Symfony Inflector Component
symfony/intl                             v4.3.1    A PHP replacement layer for the C intl extension that includes additional data from the ICU library.
symfony/maker-bundle                     v1.11.6   Symfony Maker helps you create empty commands, controllers, form classes, tests and more so you can forget about writing boilerplate ...
symfony/mime                             v4.3.1    A library to manipulate MIME messages
symfony/monolog-bridge                   v4.2.9    Symfony Monolog Bridge
symfony/monolog-bundle                   v3.3.1    Symfony MonologBundle
symfony/options-resolver                 v4.3.1    Symfony OptionsResolver Component
symfony/orm-pack                         v1.0.6    A pack for the Doctrine ORM
symfony/panther                          v0.4.1    A browser testing and web scraping library for PHP and Symfony.
symfony/phpunit-bridge                   v4.3.1    Symfony PHPUnit Bridge
symfony/polyfill-intl-icu                v1.11.0   Symfony polyfill for intl's ICU-related data and classes
symfony/polyfill-intl-idn                v1.11.0   Symfony polyfill for intl's idn_to_ascii and idn_to_utf8 functions
symfony/polyfill-mbstring                v1.11.0   Symfony polyfill for the Mbstring extension
symfony/polyfill-php72                   v1.11.0   Symfony polyfill backporting some PHP 7.2+ features to lower PHP versions
symfony/polyfill-php73                   v1.11.0   Symfony polyfill backporting some PHP 7.3+ features to lower PHP versions
symfony/process                          v4.2.9    Symfony Process Component
symfony/profiler-pack                    v1.0.4    A pack for the Symfony web profiler
symfony/property-access                  v4.3.1    Symfony PropertyAccess Component
symfony/property-info                    v4.3.1    Symfony Property Info Component
symfony/routing                          v4.3.1    Symfony Routing Component
symfony/security-acl                     v3.0.2    Symfony Security Component - ACL (Access Control List)
symfony/security-bundle                  v4.2.9    Symfony SecurityBundle
symfony/security-core                    v4.2.9    Symfony Security Component - Core Library
symfony/security-csrf                    v4.3.1    Symfony Security Component - CSRF Library
symfony/security-guard                   v4.2.9    Symfony Security Component - Guard
symfony/security-http                    v4.2.9    Symfony Security Component - HTTP Integration
symfony/serializer                       v4.3.1    Symfony Serializer Component
symfony/serializer-pack                  v1.0.2    A pack for the Symfony serializer
symfony/stopwatch                        v4.3.1    Symfony Stopwatch Component
symfony/swiftmailer-bundle               v3.2.7    Symfony SwiftmailerBundle
symfony/templating                       v4.3.1    Symfony Templating Component
symfony/test-pack                        v1.0.5    A pack for functional and end-to-end testing within a Symfony app
symfony/translation                      v4.2.9    Symfony Translation Component
symfony/twig-bridge                      v4.2.9    Symfony Twig Bridge
symfony/twig-bundle                      v4.2.9    Symfony TwigBundle
symfony/validator                        v4.2.9    Symfony Validator Component
symfony/var-dumper                       v4.3.1    Symfony mechanism for exploring and dumping PHP variables
symfony/var-exporter                     v4.3.1    A blend of var_export() + serialize() to turn any serializable data structure to plain PHP code
symfony/web-link                         v4.2.9    Symfony WebLink Component
symfony/web-profiler-bundle              v4.2.9    Symfony WebProfilerBundle
symfony/web-server-bundle                v4.2.9    Symfony WebServerBundle
symfony/yaml                             v4.2.9    Symfony Yaml Component

PHP version

$ php -v
PHP 7.2.19-0ubuntu0.18.04.1 (cli) (built: Jun  4 2019 14:48:12) ( NTS )

Code

<?php
namespace App\Admin;
use Sonata\AdminBundle\Admin\AbstractAdmin;
use Sonata\AdminBundle\Datagrid\ListMapper;
use Sonata\AdminBundle\Datagrid\DatagridMapper;
use Sonata\AdminBundle\Form\FormMapper;
use Symfony\Component\Form\Extension\Core\Type\TextareaType;
use Symfony\Component\Form\Extension\Core\Type\TextType;

final class BusinessAdmin extends AbstractAdmin
{
    protected function configureFormFields(FormMapper $formMapper)
    {
        $formMapper
            ->tab('Business')
                ->with('General', ['class' => 'col-md-6 col-xs-12'])
                    ->add('name', TextType::class)
                    ->add('website', TextType::class)
                ->end()
                ->with('Profile', ['class' => 'col-md-6 col-xs-12'])
                    ->add('business_hours', TextType::class)
                ->end()
            ->end();
        $formMapper
            ->tab('Addresses')
                ->with('General', ['class' => 'col-md-6 col-xs-12'])
                    ->add('city', TextType::class)
                    ->add('address', TextareaType::class)
                    ->add('latitude', TextType::class)
                    ->add('longitude', TextType::class)
                ->end()
            ->end();
    }

    protected function configureDatagridFilters(DatagridMapper $datagridMapper)
    {
        $datagridMapper
            ->add('id')
            ->add('name');
    }
    protected function configureListFields(ListMapper $listMapper)
    {
        $listMapper
            ->addIdentifier('name', 'text', ['label' => 'Name','editable'=>true])
            ->add('createdAt')
            ->add('updatedAt');
    }
}
services:
    _defaults:
        autowire: true  
        autoconfigure: true
        public: true

Is there anything changed, I need to add ?

bug unconfirmed

Most helpful comment

This bundle doesn't have native support for autoconfiguration on admin services. You must define your services explicitly or try with kunicmarko/sonata-auto-configure-bundle to autoconfigure your admin services.

All 2 comments

This bundle doesn't have native support for autoconfiguration on admin services. You must define your services explicitly or try with kunicmarko/sonata-auto-configure-bundle to autoconfigure your admin services.

I'm closing this issue based on the previous response. Please feel free to reopen if you think there is something missing about the feedback.
Thank you!

Was this page helpful?
0 / 5 - 0 ratings