genemu / GenemuFormBundle

Extra Form : Captcha GD, Tinymce, Recaptcha, JQueryDate, JQueryAutocomplete, JQuerySlider, JQueryFile, JQueryImage
587 stars 265 forks source link

autocompleter and symfony.2.7? #406

Open scottshipman opened 8 years ago

scottshipman commented 8 years ago

I get the following error when I implement genemu_jqueryautocompleter_entity, but no errors when I implement genemu_jqueryautocomplete_entity. The salesAgent and secondaryContact fields are identical definitions, and swapping fields makes no difference.

Catchable Fatal Error: Argument 1 passed to Genemu\Bundle\FormBundle\Form\Core\DataTransformer\ChoiceToJsonTransformer::__construct() must implement interface Symfony\Component\Form\Extension\Core\ChoiceList\ChoiceListInterface, instance of Symfony\Component\Form\ChoiceList\LegacyChoiceListAdapter given, called in /srv/www/Toolkit/vendor/genemu/form-bundle/Genemu/Bundle/FormBundle/Form/JQuery/Type/AutocompleterType.php on line 46 and defined

$builder
            //works
            ->add('salesAgent', 'genemu_jqueryautocomplete_entity', array(
                'required' => false,
                'class' => 'MyApp\UserBundle\Entity\User',
                'route_name' => 'retrieve_salesagent_name',
                'data_class' => 'MyApp\UserBundle\Entity\User'
            ))
            // generates error
            ->add('secondaryContact', 'genemu_jqueryautocompleter_entity', array(
              'class' => 'MyApp\UserBundle\Entity\User',
              'required' => false,
              'route_name' => 'retrieve_salesagent_name',
              'data_class' => 'MyApp\UserBundle\Entity\User',
              'multiple' => true,
            ))

using symfony v 2.7 genemu/form-bundle dev-master (2.3.x-dev)

wetternest commented 8 years ago

same here, using genemu/form-bundle v2.2.2 with symfony v2.7.3

aureliengiry commented 8 years ago

Yes, I have the same issue. It's because Choice form has been completely refactored in Symfony 2.7 http://symfony.com/blog/new-in-symfony-2-7-choice-form-type-refactorization

In class, Genemu\Bundle\FormBundle\Form\Core\DataTransformer, now, $choiceList is an instance of LegacyChoiceListAdapter

this is a beginning of fix:

use Symfony\Component\Form\ChoiceList\LegacyChoiceListAdapter;

  /**
     * Constructs
     *
     * @param ArrayChoiceList $choiceList
     * @param boolean         $ajax
     */
    public function __construct($choiceList, $ajax = false, $widget = 'choice', $multiple = false)
    {
        if ($choiceList instanceof LegacyChoiceListAdapter){
            $this->choiceList = $choiceList->getAdaptedList();
        }
        else if($choiceList instanceof ChoiceListInterface){
            $this->choiceList = $choiceList;
        }

        $this->ajax = $ajax;
        $this->multiple = $multiple;
        $this->widget = $widget;
    }

I took exemple on Sonata Admin bundle (Sonata\AdminBundle\Form\DataTransformer). But I have now another error. Notice: Undefined offset: 1 on file in vendor/symfony/symfony/src/Symfony/Component/Form/ChoiceList/Factory/DefaultChoiceListFactory.php at line 213

regards,

lealceldeiro commented 8 years ago

Please, if anyone find out how to solve this, let us know. I'm having the same problem with this bundle with Symfony 2.7.7.

Regards.

webdevilopers commented 8 years ago

Should be closed @genemu in favor of https://github.com/genemu/GenemuFormBundle/issues/412

Current workaround by @aimeric: https://github.com/genemu/GenemuFormBundle/issues/412#issuecomment-169946398