sonata-project / SonataUserBundle

Symfony SonataUserBundle
https://docs.sonata-project.org/projects/SonataUserBundle
MIT License
342 stars 487 forks source link

Type error: Argument 1 passed to Symfony\Component\Form\FormRenderer::setTheme() must be an instance of Symfony\Component\Form\FormView, null given #878

Closed anboo closed 6 years ago

anboo commented 7 years ago

Environment

Sonata packages

$ composer show sonata-project/*
sonata-project/admin-bundle              3.18.0 The missing Symfony Admin Generator
sonata-project/block-bundle              3.3.2  Symfony SonataBlockBundle
sonata-project/cache                     1.0.7  Cache library
sonata-project/core-bundle               3.3.0  Symfony SonataCoreBundle
sonata-project/datagrid-bundle           2.2.1  Symfony SonataDatagridBundle
sonata-project/doctrine-orm-admin-bundle 3.1.4  Symfony Sonata / Integrate Doctrine ORM into the SonataAdminBundle
sonata-project/exporter                  1.7.1  Lightweight Exporter library
sonata-project/seo-bundle                2.1.0  Symfony SonataSeoBundle

Symfony packages

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

PHP version

$ php -v
PHP 7.1.4-1+deb.sury.org~trusty+1 (cli) (built: Apr 11 2017 22:45:20) ( NTS )
Copyright (c) 1997-2017 The PHP Group
Zend Engine v3.1.0, Copyright (c) 1998-2017 Zend Technologies
    with Zend OPcache v7.1.4-1+deb.sury.org~trusty+1, Copyright (c) 1999-2017, by Zend Technologies
    with Xdebug v2.5.1, Copyright (c) 2002-2017, by Derick Rethans

Subject

Steps to reproduce

HouseAdmin.php:

$formMapper
                ->with('Images', ['class' => 'col-md-6'])
                    ->add('images', 'sonata_type_collection', [], [
                        'edit' => 'inline',
                        'inline' => 'table',
                        'sortable' => 'position',
                    ])
                ->end()
            ;

ImageAdmin.php:

$formMapper
            ->add('imageFile', VichImageType::class, [
                'required' => false,
                'by_reference' => true,
            ], [
                'allow_delete' => false,
                'download_link' => true,
                'by_reference' => true,
            ])
            ->add('caption')
            ->add('house', null, [
                'disabled' => true
            ])
        ;

House.php:

     /**
     * @ORM\OneToMany(targetEntity="PropertyBundle\Entity\Image", mappedBy="house", cascade={"persist", "remove"}, orphanRemoval=true)
     */
    private $images;

    /**
     * Add image
     *
     * @param \PropertyBundle\Entity\Image $image
     *
     * @return House
     */
    public function addImage(\PropertyBundle\Entity\Image $image)
    {
        $image->setHouse($this);

        $this->images[] = $image;

        return $this;
    }

    /**
     * Remove image
     *
     * @param \PropertyBundle\Entity\Image $image
     */
    public function removeImage(\PropertyBundle\Entity\Image $image)
    {
        $this->images->removeElement($image);
    }

Image.php:

     /**
     * @ORM\ManyToOne(targetEntity="PropertyBundle\Entity\House", inversedBy="images")
     */
    private $house;

     /**
     * Set house
     *
     * @param \PropertyBundle\Entity\House $house
     *
     * @return Image
     */
    public function setHouse(\PropertyBundle\Entity\House $house = null)
    {
        $this->house = $house;

        return $this;
    }

    /**
     * Get house
     *
     * @return \PropertyBundle\Entity\House
     */
    public function getHouse()
    {
        return $this->house;
    }

Expected results

Correct, without errors :)

Actual results

Incorrect froms :) alt text

anboo commented 7 years ago

URL: http://real.dev/admin/core/append-form-field-element?code=property.admin.house&elementId=s5919a4efc66a8_images&objectId=1&uniqid=s5919a4efc66a8

haivala commented 7 years ago

I have the same problem. In my case the Admin generated that error when the form was done like this:

protected function configureFormFields(FormMapper $formMapper)
...
       if ($this->isCurrentRoute('edit')) {
         $formMapper->add('something', 'sonata_type_collection', 
                        array('required' => false, 'by_reference' => false),
                        array('edit' => 'inline', 'inline' => 'table')
                    );
       }

If its out of the route check, it works..

OskarStark commented 7 years ago

Why does this issue belongs to the Userbundle?

haivala commented 7 years ago

It does not.. I just googled the error and found this

danielantelo commented 6 years ago

@haivala did you ever find a way of using the route check as you showed? I am having the same issue, this is the only thread i found with the exact same problem i am facing. Thanks!

jordisala1991 commented 6 years ago

Try updating admin bundle to the latest version, and probably all the other sonata bundles too.

Closing because this does not belong to user-bundle.

ilyaskereibayev commented 3 years ago

I have the same problem. In my case the Admin generated that error when the form was done like this:

protected function configureFormFields(FormMapper $formMapper)
...
       if ($this->isCurrentRoute('edit')) {
         $formMapper->add('something', 'sonata_type_collection', 
                        array('required' => false, 'by_reference' => false),
                        array('edit' => 'inline', 'inline' => 'table')
                    );
       }

If its out of the route check, it works..

This makes it work if($this->isCurrentRoute('edit') || $this->getRequest()->get('_route') === 'sonata_asadmin_append_form_element'))