Limenius / LiformBundle

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

undefined method named "getBlockPrefix" #3

Closed github-mathieu-salles closed 7 years ago

github-mathieu-salles commented 7 years ago

Got this error when I tried to generate a schema with liform :

CRITICAL - Uncaught PHP Exception Symfony\Component\Debug\Exception\UndefinedMethodException: "Attempted to call an undefined method named "getBlockPrefix" of class "Symfony\Component\Form\Extension\DataCollector\Proxy\ResolvedTypeDataCollectorProxy"." at /home/admin/Documents/displayce/code/vendor/limenius/liform/src/Limenius/Liform/FormUtil.php line 39

Here my two code lines : $editForm = $this->createForm(new EditType(), $entity, array( 'method' => 'PUT', 'csrf_protection' => false, )); $schema = json_encode($this->get('liform')->transform($editForm));

I saw a bug related to that and it seems to be fixed with 2.8 version but of course my project is using 2.7 : https://github.com/symfony/symfony/issues/15760

github-mathieu-salles commented 7 years ago

A lead I have is that my editForm is a nested form :

public function buildForm(FormBuilderInterface $builder, array $options) { $builder ->add('name', 'text', array( 'label' => 'Name', 'max_length' => 255, )) ->add('target', 'targeting', array( 'cascade_validation' => true, )); }

nacmartin commented 7 years ago

Aw, yes. All of this will break in Sf < 2.8, because it introduced major changes in the form component. I have been trying to do a quick fix, but it would need more work than that. As reference, this kind of work is what would be needed https://github.com/matthiasnoback/symfony-console-form/commit/8554cdfd454ae0b6dfd8452a67199d0974b323f5#diff-4686463430e4b4932c485ab974a92154 (Note that in this case they are deprecating sf2.7, but the lines in red contain hints of what is needed to support 2.7).

nacmartin commented 7 years ago

After thinking, and as suggested in this PR, I have decided to not support 2.7, because it would require to maintain a complete different code base. It would be like maintaining two separate libs.