-
Notifications
You must be signed in to change notification settings - Fork 53
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
Error with form event listeners #295
Comments
Can you put your code, i.e. the part of |
With this code: ->addEventListener(FormEvents::POST_SUBMIT, function (PostSubmitEvent $event) {
foreach ($this->deliveryConditionsFailedToSave as $deliveryCondition) {
if ($event->getData() === $deliveryCondition) {
$event->getForm()->get('code')->addError(
new FormError("Could not change code from '{$deliveryCondition->getCode()}' to '{$event->getForm()->get('code')->getData()}'. Code '{$deliveryCondition->getCode()}' is in use.")
);
}
}
}) I get this error (on symfony 6.2, php8.1)
|
Note this happens when chaining That is
Without chaining it seems to work fine like: |
It seems to cause other errors like `UndefinedInterfaceMethod - SimpleContractlineType.php:63:15 - Method Symfony\Component\Form\FormConfigBuilderInterface::add does not exist |
OK, my bad; I just noticed you were using $builder->add()->addEventListener() and I miss-read it as $builder->addEventListener()->addEventListener() To help me the fix, can you put entire full calls you make, and all errors? Should be easy fix, just need a way to replicate it. Updated: @seferov @VincentLanglet What do you guys think? Something like nested generics in AbstractController? For example: interface FormBuilderInterface extends \Traversable, \Countable, FormConfigBuilderInterface
{
/**
* @template TChildType
* @template TFormType of FormTypeInterface<TChildType>
*
* @psalm-param class-string<TFormType> $type
*
* @psalm-return FormBuilderInterface<TChildType>
*/
public function add(string|FormBuilderInterface $child, string $type = null, array $options = []): static; I think this one would work but the problem is that |
Didn't really follow this subject but I would say to be careful when introducing generics on a plugin: Symfony started to merge PR with generics, so it could be interesting to start doing PR on symfony code base instead. |
The issue is that PHPStan doesn't yet support nested generics (I think this is the correct term) like one in $data = $this->createForm(CustomerType::class)->getData(); // mixed but psalm can correctly resolve to
Sorry, I didn't understand this one. Are you in favor of resolving it via plugin event, or via template annotation (as it is now) or nothing at all (mixed always)? We could also make an option to disable form stubs if users find this incompatibility with PHPStan a big problem. Or even remove from this repository and put into another. WDYT; is it worth it? You are more in Symfony circles than I am. |
You mean that if I'm not sure bout the support of PHPStan, I would say it's possible to do this...
I'm fine with template, but it can now be done directly on Symfony first
There is an issue with FormView template for instance, because it's not generic in PHPStan but it is in Psalm.
but PHPStan doesn't, so a stub in PHPStan codebase wouldn't make sens. I got a recent issue with Psalm 5 since now this tool report "MissingTemplate" errors which didn't exist in Psalm 4.
So I would say there is no need to provide something to disable a stubs. |
Yes, that one. I tried PHPStan to resolve this, but it always returned
There has been few attempts of merging form stubs into Symfony itself, but stof gave some good arguments. From my POV, after 2-3 years of using these stubs, I have never had a problem. Doesn't mean they don't exist but I just didn't encounter them even with complex compound forms and transformers. Did you have problems with them, assuming event listeners were used? If so, can you paste an example?
Honestly, I didn't even know about this one, thanks. Today I tried V5 and from zero errors, got 212; only 5 coming from me forgetting template on But with this, compatibility with V4 can be kept and not deter new users. |
I essentially had problem because stub was added to PHPStan or Psalm, and I had to add it to the other. |
I'm getting these errors with some form event listeners, not sure what $event is being inferred here.
The text was updated successfully, but these errors were encountered: