-
-
Notifications
You must be signed in to change notification settings - Fork 5.1k
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
How to Submit a Form with Multiple Buttons #11777
Comments
Did you run into a real issue during execution or is this about warnings some static code analyzer tools give you? |
my IDE also does not see those methods, if you mean running PHP script then no, but still this code is not correct, because it uses methods outside interface it declares to return. And also I do not think that you should show examples in official documentation that fail static analysis. Because people will start suppressing this error. Because this static check would help if button would happen to be removed or something like that. After some scratching of my head I changed code from example to something like this:
and this passes static analysis and IDE sees all methods |
Although it's true that FormInterface doesn't define the |
in example code form variable comes from:
in symfony code this method returns:
I myself use and see more often this way of creating form:
but it still returns form interface code in example would be correct, if method I would think some about this and maybe report bug in symfony core, to add this method to interface, rather than change documentation, I just thought there is other correct way to do that. But as of now do not see one. So it is more likely that it is bug in symfony. |
From the code side that's not a bug. We can just simply write the code this way as we know that a form type that is a In the docs we need to find a balance between what would make all static analyzers happy and wha adds more confusion for readers. That's why we chose to write code examples the way they are. |
+1 with LPodolski It's wierd to me that $this->createForm returns FormInterface and not another interface that expose the real Form methods. It means that we must "cast" the result of createForm into Form to access to methods like getClickedButton. Is there any reason why createForm does not return Form instead of FormInterface ? (or another Interface that From could implements). By the way thanks, for you amazing job on symfony ! |
@xabbuh we had the same discussion a few weeks ago. Can you find the issue and reference your explanation? I am currently on a phone Thanks |
see symfony/symfony#35277 (especially symfony/symfony#35277 (comment)) |
Thank you. I personnaly use the annotation solution to tell the IDE that the type is Form and not FormInterface and avoid warning. The instanceof solution use more CPU at runtime ! ;-) |
Thank you for this issue. |
Hello? This issue is about to be closed if nobody replies. |
Hey, I didn't hear anything so I'm going to close it. Feel free to comment if this is still relevant, I can always reopen! |
Documentation is incorrect in:
https://github.com/symfony/symfony-docs/blob/master/form/multiple_buttons.rst
https://symfony.com/doc/current/form/multiple_buttons.html
in code:
this method do not exists
if you use example above, that creates $form variable:
return type of $form variable would be
FormInterface
and form interface does not contain method
getClickedButton
Form
, which hasgetClieckedButton
method, thenreturns
ClickableInterface
which does not have method
getName
used in example:
The text was updated successfully, but these errors were encountered: