When creating a module, I got the following error message:
The website encountered an unexpected error. Please try again later.
InvalidArgumentException: The form argument \Drupal\my_module\Form\MyForm is not a valid form. in Drupal\Core\Form\FormBuilder->getFormId() (line 190 of core/lib/Drupal/Core/Form/FormBuilder.php).
The issue was that my form filename was not correct (it should be named MyForm.php, but if it's called MyForm_Wrong.php or something like that, the system can't find it. The error message should therefore be:
The website encountered an unexpected error. Please try again later.
InvalidArgumentException: The form argument \Drupal\my_module\Form\MyForm is not a valid form. in Drupal\Core\Form\FormBuilder->getFormId() (line 190 of core/lib/Drupal/Core/Form/FormBuilder.php). Reason: Expected form file (MyForm.php) not found in folder: my_module/src/Form
This post solved my problem, and this person also suggested a better error message should have been given: https://drupal.stackexchange.com/questions/199828/call-a-custom-form-in-node-template
p.s. apologies if I assigned this to the incorrect component. I made a guess at user.modules.
As ever, huge thanks :)
Comments
Comment #2
cilefen CreditAttribution: cilefen commentedBefore adding tags read the issue tag guidelines. Feature requests go in 8.4.x at this phase. This is the forms system.
Comment #9
Ramya Balasubramanian CreditAttribution: Ramya Balasubramanian at Srijan | A Material+ Company for Drupal India Association commentedComment #10
Ramya Balasubramanian CreditAttribution: Ramya Balasubramanian at Srijan | A Material+ Company for Drupal India Association commentedI can't able to reproduce the issues. So I am unassigning this ticket.