genemu / GenemuFormBundle

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

How do I use this bundle in Symfony 3.1? #435

Open ozzmaster opened 7 years ago

ozzmaster commented 7 years ago

This is my old Form Builder code:

public function buildForm(FormBuilderInterface $builder, array $options) {
    ...
    $builder->add(
                'redeemed_at', 'genemu_jqueryselect2_choice',
                array('label' =>'Voucher Redeemed At: *', 'choices' => $dealerships, 'mapped' => false)
        );
    ...
}

If I use this, as per the examples and as I do in Symfony 2.x projects, Symfony 3.1 gives me this: Could not load type "genemu_jqueryselect2_choice"

After I used the new style and scratched around in this bundle for the correct form class, I tried this:

public function buildForm(FormBuilderInterface $builder, array $options) {
    ...
    $builder->add(
                'redeemed_at', Select2Type::class,
                array('label' =>'Voucher Redeemed At: *', 'choices' => $dealerships, 'mapped' => false)
        );
    ...
}

Now I get this: Warning: Missing argument 1 for Genemu\Bundle\FormBundle\Form\JQuery\Type\Select2Type::__construct()

Is that the correct class?

I would really prefer to use this bundle, as I have in the past, instead of abandoning it!

PLEASE HELP!

ghost commented 7 years ago

Do you have already found a solution for that?

ozzmaster commented 7 years ago

No. I implemented Select2 by specifying a normal 'choice' type and then adding the necessary Javascript files and calls to the form template. I would still appreciate a solution as I have other projects that I want to upgrade to Symfony 3.x from Symfony 2.x. They are all using this bundle.

zigomario commented 7 years ago

I have exactly same problem. i have find how to bypass it. In the file directly .... we define $ widget in the constructor with the desired type. Example, I need EntityType with select2 :

public function __construct($widget ='Entity', array $configs = array())
    {
        $this->widget = $widget;
        $this->configs = $configs;
    }

We agree, it's ugly and totally forbidden to do that. But as I am a newbie with POO, I do not understand :

XxxTYPE :: class

what is ":: class"?

benschumi commented 7 years ago

Although it is marked compliant 3.X, it is not.

I fork and rewrite the bundle to be compatible waiting for a compatible version.

Kanouille commented 7 years ago

Hi, First, thanks @benschumi to working on a compatible version. But in the meantime, I think I found a clean solution for waiting your PR. But I need your feedback for this.

I needed only genemu_jqueryselect2 forms. So, i created a formType extends Select2Type. Example:

use Genemu\Bundle\FormBundle\Form\JQuery\Type\Select2Type;

/**
 * Select2EntityType
 */
class Select2EntityType extends Select2Type
{
    /**
     * The constructor
     */
    public function __construct()
    {
        parent::__construct('entity');
    }
}

I had no specific configurations into my config.yml for genum_form.select2. So, I assumed this simple object could overload the service generate by GenemuFormExtension, and it works. I can use this formType to replace the generic service 'genemu_jqueryselect2_entity'.

Can you confirm that works for your too ?

Stoakes commented 7 years ago

Hi,

I know that issue is rather old, but it seems that @benschumi /form-bundle isn't refered in Packagist anymore. Is it normal ?

Thanks

benschumi commented 7 years ago

Hi,

I never put it on Packagist.

rusanter commented 7 years ago

@benschumi, sorry for writing to you here, but I can't find the right place. Can you please add "replace" section to a composer.json and list genemu/form-bundle there. For more information, see https://getcomposer.org/doc/04-schema.md#replace

benschumi commented 7 years ago

I can't put a fork on packagist,

Do not submit forks of existing packages. If you need to test changes to a package that you forked to patch, use VCS Repositories instead.

If you want to use my fork, use vcs insteasd

{ "repositories": [ { "type": "vcs", "url": "https://github.com/benschumi/form-bundle" } ] }

rusanter commented 7 years ago

@benschumi Sure I use your version exactly this way. I also want to add more dependencies which require genemu/form-bundle. And I want them to happily work with your version. That's why I'm asking you about replacing genemu/form-bundle in composer.json.