Limenius / LiformBundle

Symfony Bundle to render Symfony Forms to JSON Schema
MIT License
138 stars 43 forks source link

Does not support full range of native FormTypes - Symfony 4.3.4 #23

Open AndrewMacKay-base opened 4 years ago

AndrewMacKay-base commented 4 years ago

I'm uncertain whether the issue I'm experiencing is because my current version of Symfony 4.3.4 is unsupported by this bundle, or due to some specific implementation issue in our installation, or whether actually the bundle does not support all the different types included by Symfony.

use Limenius\Liform\Resolver;
use Limenius\Liform\Liform;
use Limenius\Liform\Liform\Transformer;
...
public function edit(Activity $activity, Liform $liform, Request $request)
    {
    // $builder->add('startDate', DateType::class, [
    $form = $this->createForm(ActivityFormType::class, $activity, []);
    $schema = $liform->transform($form);
...
}

The above pattern works as expected for TextType, and ChoiceType, but falls over for DateType with the error

"Could not find a transformer for any of these types (date, form) "

The documenation does not make it clear whether I should expect this functionality to exist. It suggests I will need to add custom work to include custom extension, however seems to imply that it should work out the box with a standard Symfony install.

I notice that DateType and EntityType do not seem to be in the list of available transformers here.

https://github.com/Limenius/LiformBundle/blob/master/Resources/config/transformers.xml

Am I correct then in my understanding that DateType which is a standard Symfony type is not supported? https://symfony.com/doc/current/reference/forms/types/date.html

Edit Also from here http://nacho-martin.com/serializing-symfony-forms-to-json-schema.html This overview seems to imply dates are supported ->add('dueTo', Type\DateTimeType::class, [ Using the DateTimeType we get a similar error Could not find a transformer for any of these types (datetime)

phpwutz commented 4 years ago

I'm facing the same problem, this was working fine in 0.13, but upgrading to 0.15 broke it. I very much assume it's got something to do with this "fix": https://github.com/Limenius/LiformBundle/commit/8c54258d2ba1b77c00c75c966641554f9fef80d6

I've helped myself for now to restore the "old" behavior by adding custom transformers in services.yml:

services:
    app.liform.datetime_type.transformer:
        class: Limenius\Liform\Transformer\StringTransformer
        parent: Limenius\Liform\Transformer\AbstractTransformer
        tags:
            - { name: liform.transformer, form_type: datetime, widget: datetime }
    app.liform.date_type.transformer:
        class: Limenius\Liform\Transformer\StringTransformer
        parent: Limenius\Liform\Transformer\AbstractTransformer
        tags:
            - { name: liform.transformer, form_type: date, widget: date }