umpirsky / Symfony-Upgrade-Fixer

Analyzes your Symfony project and tries to make it compatible with the new version of Symfony framework.
MIT License
273 stars 18 forks source link

The 'collection' form type is not replaced by CollectionType::class #27

Closed XuruDragon closed 8 years ago

XuruDragon commented 8 years ago

I've just run your tool and the 'collection' form type is not replaced by CollectionType::class.

umpirsky commented 8 years ago

@XuruDragon Thanks for reporting. That's strange, it should be (https://github.com/umpirsky/Symfony-Upgrade-Fixer/blob/3c117ab4f1778eadaafa73d0434238f96bddbf87/src/Symfony/Upgrade/Fixer/FormTypeFixer.php#L14).

Can you share your form type code or submit failing test please?

XuruDragon commented 8 years ago

Hi @umpirsky,

Here is the code of the form :

switch ($nb) {
            case 31:
                $form = $this->createFormBuilder($array_lignes)
                    ->setMethod('POST')
                    ->add('lignescon', 'collection', array(
                        'type' => new Ligne31Form(),
                        'options' => array(),
                    ))
                    ->add('lignescra', 'collection', array(
                        'type' => new Ligne31Form(),
                    ))
                    ->getForm();
                break;
.........

after the correction :

switch ($nb) {
            case 31:
                $form = $this->createFormBuilder($array_lignes)
                    ->setMethod('POST')
                    ->add('lignescon', CollectionType::class, array(
                        'entry_type' => Ligne31Form::class,
                        'entry_options' => array(),
                    ))
                    ->add('lignescra', CollectionType::class, array(
                        'entry_type' => Ligne31Form::class,
                    ))
                    ->getForm();
                break;
.........

Any test as been possible since the symfony raise an exception if it not in the rigth type. I'm working with Symfony3.0.4.

Nb: It would be nice that the keys 'type' and 'options' was transform to 'entry_type' and 'entry_options' for an collection type

umpirsky commented 8 years ago

@XuruDragon Can you please provide entire class? Or at least tell me what class does your form type extends? Thanks.

XuruDragon commented 8 years ago

@umpirsky the code above is in a controller.

My Ligne31Form class :

<?php
namespace Ajeel\CraBundle\Form;

use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\HiddenType;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;

class Ligne31Form extends AbstractType
{
    public function buildForm(FormBuilderInterface $builder, array $options)
    {
        $builder->add('id', HiddenType::class, array('label' => '', 'attr' => array('class' => 'input_cra')))
            ->add('j1', TextType::class, array('label' => '', 'attr' => array('class' => 'input_cra')))
            ->add('j2', TextType::class, array('label' => '', 'attr' => array('class' => 'input_cra')))
            ->add('j3', TextType::class, array('label' => '', 'attr' => array('class' => 'input_cra')))
            ->add('j4', TextType::class, array('label' => '', 'attr' => array('class' => 'input_cra')))
            ->add('j5', TextType::class, array('label' => '', 'attr' => array('class' => 'input_cra')))
            ->add('j6', TextType::class, array('label' => '', 'attr' => array('class' => 'input_cra')))
            ->add('j7', TextType::class, array('label' => '', 'attr' => array('class' => 'input_cra')))
            ->add('j8', TextType::class, array('label' => '', 'attr' => array('class' => 'input_cra')))
            ->add('j9', TextType::class, array('label' => '', 'attr' => array('class' => 'input_cra')))
            ->add('j10', TextType::class, array('label' => '', 'attr' => array('class' => 'input_cra')))
            ->add('j11', TextType::class, array('label' => '', 'attr' => array('class' => 'input_cra')))
            ->add('j12', TextType::class, array('label' => '', 'attr' => array('class' => 'input_cra')))
            ->add('j13', TextType::class, array('label' => '', 'attr' => array('class' => 'input_cra')))
            ->add('j14', TextType::class, array('label' => '', 'attr' => array('class' => 'input_cra')))
            ->add('j15', TextType::class, array('label' => '', 'attr' => array('class' => 'input_cra')))
            ->add('j16', TextType::class, array('label' => '', 'attr' => array('class' => 'input_cra')))
            ->add('j17', TextType::class, array('label' => '', 'attr' => array('class' => 'input_cra')))
            ->add('j18', TextType::class, array('label' => '', 'attr' => array('class' => 'input_cra')))
            ->add('j19', TextType::class, array('label' => '', 'attr' => array('class' => 'input_cra')))
            ->add('j20', TextType::class, array('label' => '', 'attr' => array('class' => 'input_cra')))
            ->add('j21', TextType::class, array('label' => '', 'attr' => array('class' => 'input_cra')))
            ->add('j22', TextType::class, array('label' => '', 'attr' => array('class' => 'input_cra')))
            ->add('j23', TextType::class, array('label' => '', 'attr' => array('class' => 'input_cra')))
            ->add('j24', TextType::class, array('label' => '', 'attr' => array('class' => 'input_cra')))
            ->add('j25', TextType::class, array('label' => '', 'attr' => array('class' => 'input_cra')))
            ->add('j26', TextType::class, array('label' => '', 'attr' => array('class' => 'input_cra')))
            ->add('j27', TextType::class, array('label' => '', 'attr' => array('class' => 'input_cra')))
            ->add('j28', TextType::class, array('label' => '', 'attr' => array('class' => 'input_cra')))
            ->add('j29', TextType::class, array('label' => '', 'attr' => array('class' => 'input_cra')))
            ->add('j30', TextType::class, array('label' => '', 'attr' => array('class' => 'input_cra')))
            ->add('j31', TextType::class, array('label' => '', 'attr' => array('class' => 'input_cra')))
            ;
    }

    public function configureOptions(OptionsResolver $resolver)
    {
        $resolver->setDefaults(array());
    }

    /**
     * Returns the name of this type.
     *
     * @return string The name of this type
     */
    public function getBlockPrefix()
    {
        return 'ligne31form';
    }
}
umpirsky commented 8 years ago

@XuruDragon Symfony Upgrade Fixer only fixes form code that is in form type classes and extends AbstractType (this needs some improvement https://github.com/umpirsky/Symfony-Upgrade-Fixer/issues/8). But fixing form code inside controllers was never on our roadmap.

Thanks.

XuruDragon commented 8 years ago

Ok thanks.