Sonataadminbundle: Could not load type "sonata_type_admin"

Created on 20 Sep 2017  路  11Comments  路  Source: sonata-project/SonataAdminBundle

Environment

Sonata packages

sonata-project/admin-bundle              3.23.0 3.23.0 The missing Symfony Admin Generator
sonata-project/block-bundle              3.4.0  3.4.0  Symfony SonataBlockBundle
sonata-project/cache                     1.0.7  1.0.7  Cache library
sonata-project/core-bundle               3.5.0  3.5.0  Symfony SonataCoreBundle
sonata-project/datagrid-bundle           2.2.1  2.2.1  Symfony SonataDatagridBundle
sonata-project/doctrine-orm-admin-bundle 3.1.7  3.1.7  Symfony Sonata / Integrate Doctrine ORM into the SonataAdminBundle
sonata-project/exporter                  1.7.1  1.7.1  Lightweight Exporter library

Symfony packages

symfony/monolog-bundle     v3.1.0 v3.1.0 Symfony MonologBundle
symfony/phpunit-bridge     v3.3.9 v3.3.9 Symfony PHPUnit Bridge
symfony/polyfill-apcu      v1.5.0 v1.5.0 Symfony polyfill backporting apcu_* functions to lower PHP versions
symfony/polyfill-intl-icu  v1.5.0 v1.5.0 Symfony polyfill for intl's ICU-related data and classes
symfony/polyfill-mbstring  v1.5.0 v1.5.0 Symfony polyfill for the Mbstring extension
symfony/polyfill-php56     v1.5.0 v1.5.0 Symfony polyfill backporting some PHP 5.6+ features to lower PHP versions
symfony/polyfill-php70     v1.5.0 v1.5.0 Symfony polyfill backporting some PHP 7.0+ features to lower PHP versions
symfony/polyfill-php72     v1.5.0 v1.5.0 Symfony polyfill backporting some PHP 7.2+ features to lower PHP versions
symfony/polyfill-util      v1.5.0 v1.5.0 Symfony utilities for portability of PHP codes
symfony/security-acl       v3.0.0 v3.0.0 Symfony Security Component - ACL (Access Control List)
symfony/swiftmailer-bundle v3.0.4 v3.0.4 Symfony SwiftmailerBundle
symfony/symfony            v3.3.9 v3.3.9 The Symfony PHP framework

PHP version

PHP 7.0.22-0ubuntu0.17.04.1 (cli) (built: Aug  8 2017 22:03:30) ( NTS )
Copyright (c) 1997-2017 The PHP Group
Zend Engine v3.0.0, Copyright (c) 1998-2017 Zend Technologies
    with Zend OPcache v7.0.22-0ubuntu0.17.04.1, Copyright (c) 1999-2017, by Zend Technologies

Subject

I get an error message

Steps to reproduce

my form:

/**
     * {@inheritdoc}
     */
    protected function configureFormFields(FormMapper $formMapper)
    {
        $formMapper
            ->add('subject')
            ->add('leadPersons', \Sonata\CoreBundle\Form\Type\CollectionType::class, array(
                'by_reference' => false,
                'required' => false,
            ), array(
                'edit' => 'inline',
                'inline' => 'table',
                'sortable' => 'position',
            ))
        ;
    }

Expected results

nice view with form

Actual results

error 500
Could not load type "sonata_type_admin"

Symfony\Component\Form\Exception\InvalidArgumentException:
Could not load type "sonata_type_admin"

  at vendor/symfony/symfony/src/Symfony/Component/Form/FormRegistry.php:87
  at Symfony\Component\Form\FormRegistry->getType('sonata_type_admin')
     (vendor/symfony/symfony/src/Symfony/Component/Form/FormFactory.php:74)
  at Symfony\Component\Form\FormFactory->createNamedBuilder(0, 'sonata_type_admin', null, array('sonata_field_description' => object(FieldDescription), 'data_class' => 'Custom\\AcademyBundle\\Entity\\BlockWorker', 'property_path' => '[0]', 'data' => object(BlockWorker), 'auto_initialize' => false))
     (vendor/symfony/symfony/src/Symfony/Component/Form/FormFactory.php:38)
  at Symfony\Component\Form\FormFactory->createNamed(0, 'sonata_type_admin', null, array('sonata_field_description' => object(FieldDescription), 'data_class' => 'Custom\\AcademyBundle\\Entity\\BlockWorker', 'property_path' => '[0]', 'data' => object(BlockWorker), 'auto_initialize' => false))
     (vendor/symfony/symfony/src/Symfony/Component/Form/Form.php:865)
  at Symfony\Component\Form\Form->add(0, 'sonata_type_admin', array('sonata_field_description' => object(FieldDescription), 'data_class' => 'Custom\\AcademyBundle\\Entity\\BlockWorker', 'property_path' => '[0]', 'data' => object(BlockWorker), 'auto_initialize' => false))
     (vendor/sonata-project/core-bundle/Form/EventListener/ResizeFormListener.php:109)
  at Sonata\CoreBundle\Form\EventListener\ResizeFormListener->preSetData(object(FormEvent), 'form.pre_set_data', object(EventDispatcher))
  at call_user_func(array(object(ResizeFormListener), 'preSetData'), object(FormEvent), 'form.pre_set_data', object(EventDispatcher))
     (vendor/symfony/symfony/src/Symfony/Component/EventDispatcher/EventDispatcher.php:212)
  at Symfony\Component\EventDispatcher\EventDispatcher->doDispatch(array(array(object(ResizeFormListener), 'preSetData')), 'form.pre_set_data', object(FormEvent))
     (vendor/symfony/symfony/src/Symfony/Component/EventDispatcher/EventDispatcher.php:44)
  at Symfony\Component\EventDispatcher\EventDispatcher->dispatch('form.pre_set_data', object(FormEvent))
     (vendor/symfony/symfony/src/Symfony/Component/EventDispatcher/ImmutableEventDispatcher.php:43)
  at Symfony\Component\EventDispatcher\ImmutableEventDispatcher->dispatch('form.pre_set_data', object(FormEvent))
     (vendor/symfony/symfony/src/Symfony/Component/Form/Form.php:341)
  at Symfony\Component\Form\Form->setData(object(PersistentCollection))
     (vendor/symfony/symfony/src/Symfony/Component/Form/Extension/Core/DataMapper/PropertyPathMapper.php:57)
  at Symfony\Component\Form\Extension\Core\DataMapper\PropertyPathMapper->mapDataToForms(object(Block), object(RecursiveIteratorIterator))
     (vendor/symfony/symfony/src/Symfony/Component/Form/Form.php:385)
  at Symfony\Component\Form\Form->setData(object(Block))
     (src/Custom/AppBundle/Controller/BaseAdminController.php:189)
  at Custom\AppBundle\Controller\BaseAdminController->editAction('4')
  at call_user_func_array(array(object(BaseAdminController), 'editAction'), array('4'))
     (vendor/symfony/symfony/src/Symfony/Component/HttpKernel/HttpKernel.php:153)
  at Symfony\Component\HttpKernel\HttpKernel->handleRaw(object(Request), 1)
     (vendor/symfony/symfony/src/Symfony/Component/HttpKernel/HttpKernel.php:68)
  at Symfony\Component\HttpKernel\HttpKernel->handle(object(Request), 1, true)
     (vendor/symfony/symfony/src/Symfony/Component/HttpKernel/Kernel.php:171)
  at Symfony\Component\HttpKernel\Kernel->handle(object(Request))
     (public/app_dev.php:29)

Most helpful comment

All 11 comments

Please provide the whole stack trace

The solution to the problem is:

  • Updating sonata-project/core-bundle (3.5.0 => 3.4.0): Loading from cache
  • Updating sonata-project/block-bundle (3.4.0 => 3.3.2): Downloading (100%)

It's probably because it uses the form name (sonata_type_admin) instead of the FQCN. Can you please find where this name comes from?

I do not know. In my code such text does not occur.
Maybe in Sonata\CoreBundle\Form\Type\CollectionType?

You can use the stack trace + the debugger to find where it comes from: start from vendor/sonata-project/core-bundle/Form/EventListener/ResizeFormListener.php:109

I think the problem is in the class
Sonata\CoreBundle\Form\Type\CollectionType::class

Can you please elaborate?

In my code there is no "sonata_type_admin", so it must be in Sonata\CoreBundle\Form\Type\CollectionType or somewhere higher, maybe in configuration

now it is working

Was this page helpful?
0 / 5 - 0 ratings