-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
FormType mapping for array on TextType not longer working #29809
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
Comments
This looks expected to me. What would expect instead? |
@xabbuh I know that its a miss usage of TextType but I can't find any alternative to submit unstructured set of data. I thought maybe following could do the job: $builder->add('structure', FormType::class, ['property_path' => 'structure.stagedData']); But then I got a So what I'm basically searching for is for a UnstructuredType, ArrayType or DataType or something like that. I tried to build one myself but could not get it to work maybe you can give me any hint. |
@xabbuh if I do something like the following it works currently but I'm afraid that in a future symfony release this will also crash? namespace Sulu\Bundle\ContentBundle\Form\Type;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\OptionsResolver\OptionsResolver;
class UnstructuredType extends AbstractType
{
public function configureOptions(OptionsResolver $resolver)
{
$resolver->setDefaults(array(
'compound' => false,
'multiple' => true,
));
}
} $builder->add('structure', UnstructuredType::class, ['property_path' => 'structure.stagedData']); |
@xabbuh as the logic is now based on |
@alexander-schranz I don't think that's such a great idea. A |
Yeah, I don't think that should be part of the core. |
I am trying to do something like:
But I am getting that Update |
let's close here as there is nothing to fix |
Yeah, but it's a major nuisance. Again. It's the fourth minor version of Symfony 3.4 LTS that I have to add a conflict entry for, because suddenly you're being stricter than before on a point release. I know, people shouldn't have abused this in the first place, but it's starting to make me lose trust in Semantic Versioning and the updateability of Symfony. |
I am sorry for the extra work this costs you, but effectively every bugfix is a BC break as there could always be someone relying on the wrong behaviour. |
Okay, that's true. I didn't see it that way. Thank you! |
@xabbuh do you think it would be possible to add a unstructered type to the symfony core, it would make it for me more not feeling as a hack if there is such a type in symfony core which is tested. |
I'd rather not want to do this. IMO in most of the cases such a form type means that you do not know what data to expect making validation nearly impossible. From my experience that's not really a common use case. |
@xabbuh maybe just a TestUnstructuredType so its at least tested that it works with unstructured data? |
Any near fix? Really affected here. Thanks |
Same issue here. Using RestBundle like explained here: https://symfony.com/doc/master/bundles/FOSRestBundle/2-the-view-layer.html#data-transformation So, afaics this change causes issue with the RestBundle. Using the workaround as proposed by @alexander-schranz works for me. |
Well, you should consider to "fix" that issue for LTS and add UnstructuredType in later releases - for example I was using |
@kadet1090 the stricter validation for arrays was here to solve cases where crafted requests (sending unexpected data in fields where the backend expected something else) could lead to bugs and even to a security issue (depending on what gets done with the data). |
I completely agree with the "why" it should not be a "TextType"... it is indeed the right mindset and the obvious thing for this type is to receive a scalar. What I guess some are arguing here (and I concur) is that an alternative should exist (in the core, not 'boilerplated').. to the case when you are actually expecting something like a plain array on top of which you will operate in an XYZ way. If Symfony itself was thought with the idea of moving away from these types of scenarios then I guess it's something we are going to have to live without as it goes against its values. My two cents. |
@stof Well, I totally see the point and I'm not arguing that the bug was that it was possible not that it's not possible anymore. But it's also a BC break and BC breaks in LTS versions are not a good thing. There is also the thing that it is not well documented how to pass unstructured data to form (which can be useful for exmaple when interacting with react or some really complex not really defined json structures) and for me passing |
regarding on what @xabbuh mention above
IMHO braking production applications it's even worse, and either or not it's the expected behaviour; it has been there for a long, long time; and what really brakes its the BC symfony promise. |
I must jump on the BC break, too. The update broke a (some years ago not that well built) form in our app. What about reverting the patch and adding a deprecation instead? |
@althaus Well, you could fix your Symfony version to 3.4.20 and refactor that form in the meantime to be compatible with 3.4.21+. |
@YetiCGN I've already implemented that |
I appreciate if you could provide some feedback on #29911. |
I'd appreciate if everyone affected by the issue described here could give their feedback on #29911. :) Please note that we are not going to change the behaviour of the |
Not sure if it is too late for this but just would like to share my work around solution. Not super pretty, but it works for all cases. I don't do custom type as it will take tooooo much effort to create all data types and maintain them. Unless Symfony4 unlock the In Controller
In Entity Class
In your Form
|
As I stumbled on the same error: Using a legacy TypeGuesser could be another way to support the old behavior. The custom LegacyArrayFormType:
And the type guesser (do not forget to add as service if needed):
|
Symfony version(s) affected: 4.2.2, 4.1.10, 3.4.21
Description
Since the last release the following error appears when submitting array data to the TextType:
How to reproduce
Submit an array as data
structure
for the TextType.e.g.:
This did work until the last release.
Possible Solution
Not sure is there another formType which can just be used for mapping the data instead of TextType?
Additional context
The following PR #29307 did add the breaking change.
The text was updated successfully, but these errors were encountered: