symfony2admingenerator / AvocodeFormExtensionsBundle

(old-legacy) Symfony2 form extensions for Admingenerator project (also working standalone!)
Other
48 stars 31 forks source link

[CollectionUpload] Could not load type #84

Closed denys281 closed 10 years ago

denys281 commented 10 years ago

Hi! I don't now if this bug of AvocodeForm. I have collection upload and all works. Today I start my project in new machine, so I update vendors. And collection upload gives me error

Could not load type "\Webmil\Frontend\ProductBundle\Form\ProductGalleryType"

I use last version of avocode with sf 2.3.7. I saw in update log of sf 2.3.7 but I can't find anything there, what can break my code.

gallery:
        label:            Зображення
        dbType:           collection
        formType:         afe_collection_upload
        addFormOptions:
          maxNumberOfFiles: 20
          nameable:         true 
          nameable_field:   name
          editable:         [name]
          type:             \Webmil\Frontend\ProductBundle\Form\ProductGalleryType
          acceptFileTypes:            /(\.|\/)(gif|jpe?g|png)$/i
          loadImageFileTypes:     /^image\/(gif|jpeg|png)$/
          previewMaxWidth:            100
          previewMaxHeight:           100
          previewAsCanvas:            true
          prependFiles:               false 
          allow_add:                  true
          allow_delete:               true
          options:
            data_class:    \Webmil\Frontend\ProductBundle\Entity\ProductGallery    

And my form:

<?php

namespace Webmil\Frontend\ProductBundle\Form;

use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolverInterface;

class ProductGalleryType extends AbstractType
{
    /**
     * @param FormBuilderInterface $builder
     * @param array $options
     */
    public function buildForm(FormBuilderInterface $builder, array $options)
    {
        $builder
            ->add('id', null)
            ->add('name', null);
//            ->add('imageName', null);
//            ->add('createdAt')
//            ->add('updatedAt')
//            ->add('product');
    }

    /**
     * @param OptionsResolverInterface $resolver
     */
    public function setDefaultOptions(OptionsResolverInterface $resolver)
    {
        $resolver->setDefaults(array(
            'data_class' => 'Webmil\Frontend\ProductBundle\Entity\ProductGallery'
        ));
    }

    /**
     * @return string
     */
    public function getName()
    {
        return 'webmil_frontend_productbundle_productgallerytype';
    }
}
sescandell commented 10 years ago

Please, look inside the generated form type file (in cache directory) and copy/paste the corresponding code.

Thank you,

satiricon commented 10 years ago

I had the same issue. It works if the form is declared as a service and instead of the path you just name the service in the 'type' option.

MikleDzyba commented 10 years ago

I have the same issue.

In my programm I have an object Team with collection of Members. They includes in Team-generator.yml like this:


    embed_types:
        - "Member-generator.yml"
    fields:
        members:
            label: label.members
            dbType: collection
            formType: afe_collection_table
            addFormOptions:
                type:             \My\BackBundle\Form\Type\Member\EmbedType
                allow_add:        true
                allow_delete:     true
                by_reference:     false
                error_bubbling:   false
                options:
                    data_class:     \My\FrontBundle\Entity\Member

In file "app/cache/dev/Admingenerated/MyBackBundle/Form/BaseTeamType/EditType.php" corresponding lines of code are generated (in "buildForm" method):


$formOptions = $this->getFormOption('members', array(  'required' => false,  'type' => '\\My\\BackBundle\\Form\\Type\\Member\\EmbedType',  'allow_add' => true,  'allow_delete' => true,  'by_reference' => false,  'error_bubbling' => false,  'options' =>   array(    'data_class' => '\\My\\FrontBundle\\Entity\\Member',  ),  'label' => 'label.members',  'translation_domain' => 'Team',));
$builder->add('members', 'afe_collection_table', $formOptions);

Changing the piece of code from: 'type' => '\My\BackBundle\Form\Type\Member\EmbedType' to: 'type' => new \My\BackBundle\Form\Type\Member\EmbedType() in forms subclass solves the problem.

Hope, it would help.

sescandell commented 10 years ago

This is an admingenerator bug linked to the following issues:

I'll try to push a PR to fix that case.