Limenius / LiformBundle

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

UndefinedMethodException $resolver->setDefaultTransformers(); #5

Closed BernardA closed 7 years ago

BernardA commented 7 years ago

Hello Symfony 3.4 is telling me that the method setDefaultTransformers() is not defined.

I checked Limenius\Liform\Resolver and could not find that method.

This is how my controller looks like:

`use Limenius\Liform\Resolver;
 use Limenius\Liform\Liform;

 class AdController extends Controller
{
/**
 * @Route("/nouvelle-annonce-voiture-occasion", name="new_ad_page")
 */
public function showAction(Request $request)
{
    $resolver = new Resolver();
    $resolver->setDefaultTransformers();
    $liform = new Liform($resolver);

    $ad = new Ad();
    //$form = $this->createForm(AdType::class, $ad);
    $form = $this->createForm(AdType::class, $ad);
    $schema = json_encode($liform->transform($form));
            \Doctrine\Common\Util\Debug::dump($schema);`

Also, you may notice that I removed the csrf_protection => false option from createForm as it would give me the error below. Instead I placed that option on the Type class, as follows:

public function configureOptions(OptionsResolver $resolver) { $resolver->setDefaults(array( 'data_class' => Ad::class, 'csrf_protection' => false, )); }

This is the error: (if I leave the csrf_protection where you instruct in docs)

The option "csrf_protection" does not exist. Defined options are: "action", "allow_extra_fields", "attr", "auto_initialize", "block_name", "by_reference", "compound", "constraints", "data", "data_class", "disabled", "empty_data", "error_bubbling", "error_mapping", "extra_fields_message", "inherit_data", "invalid_message", "invalid_message_parameters", "label", "label_attr", "label_format", "liform", "mapped", "method", "post_max_size_message", "property_path", "required", "translation_domain", "trim", "upload_max_size_message", "validation_groups".

Thanks

nacmartin commented 7 years ago

Hi, @BernardA I wanted to have a look at this during the weekend. How was it solved? is there something we can do so other users don't get the same error?

BernardA commented 7 years ago

HI @nacmartin . Thanks but it's mostly my fault again. I started from your Liform component and not from the bundle.

nacmartin commented 7 years ago

Ah, ok! Thanks for taking the time to answer. I split the bundle in two just in case someone is using Symfony Forms without Symfony, which is possible, but it takes more work to set up (which is what this bundle is doing).