New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Form] BC break (maybe?) between v3.4.20 and v3.4.21 #29841
Comments
looks like the same as #29809 |
Hm maybe. The difference being, instead of submitting an array structure I'm submitting a string then transforming it to an array in a form event listener. I guess both ways ultimately look the same to the form component. It's frustrating when a bugfix (was the scalar data issue really a bug or just a bad unintended feature?) causes problems like this. For anyone else running into this problem, drop the PRE_SUBMIT form event listener and add a model transformer, e.g. below: $builder->add(
$builder->create('settings', HiddenType::class)
->addModelTransformer(new JsonTransformer())
); <?php
namespace SomeRandomNamespace;
use Symfony\Component\Form\DataTransformerInterface;
class JsonTransformer implements DataTransformerInterface
{
public function transform($data)
{
if (null === $data) {
return null;
}
return json_encode($data);
}
public function reverseTransform($json)
{
if (!$json) {
return null;
}
return json_decode($json, true);
}
} |
It worked by chance - and it made any field accept arrays of values by just appending |
Well, using a Using a model data transformer is exactly how your use case should be implemented. |
I am closing here as this is not a bug as explained. |
Symfony version(s) affected: v.3.4.21
Description
Caused by #29307 (/cc @nicolas-grekas)
I've got a MainFormType that contains a collection of SubFormType. SubFormType has a hidden field that holds a JSON-encoded string (generated by JS in my actual use case). SubFormType transforms the string to an array on submit.
Everything has been working fine until 3.4.21 when the form started giving errors. I'm not really sure if this is a BC break or not, but it has definitely caused us some problems.
How to reproduce
I've created a repro branch at https://github.com/simshaun/symfony-standard/tree/form_bc_break_3.4.21
The text was updated successfully, but these errors were encountered: