Problem/Motivation
When registering for an event, none of the fields in the RegistrantForm are required. When the form is submitted without entering an email address, a fatal error occurs.
Steps to reproduce
- Create an event series.
- Enable registration.
- Go to one of the event instances and click "Register".
- Don't fill in the email address, just scroll down and press "Register" again.
Result:
TypeError: Drupal\Core\Mail\Plugin\Mail\PhpMail::doMail(): Argument #1 ($to) must be of type string, null given, called in /var/www/html/core/lib/Drupal/Core/Mail/Plugin/Mail/PhpMail.php on line 123 in Drupal\Core\Mail\Plugin\Mail\PhpMail->doMail() (line 168 of core/lib/Drupal/Core/Mail/Plugin/Mail/PhpMail.php).
Drupal\Core\Mail\Plugin\Mail\PhpMail->mail() (Line: 308)
Drupal\Core\Mail\MailManager->doMail() (Line: 181)
Drupal\Core\Mail\MailManager->Drupal\Core\Mail\{closure}() (Line: 638)
Drupal\Core\Render\Renderer->executeInRenderContext() (Line: 180)
Drupal\Core\Mail\MailManager->mail() (Line: 426)
recurring_events_registration_send_notification() (Line: 96)
Drupal\recurring_events_registration\Entity\Registrant->postSave() (Line: 563)
Drupal\Core\Entity\EntityStorageBase->doPostSave() (Line: 781)
Drupal\Core\Entity\ContentEntityStorageBase->doPostSave() (Line: 489)
Drupal\Core\Entity\EntityStorageBase->save() (Line: 806)
Drupal\Core\Entity\Sql\SqlContentEntityStorage->save() (Line: 354)
Drupal\Core\Entity\EntityBase->save() (Line: 293)
Drupal\Core\Entity\EntityForm->save() (Line: 489)
Drupal\recurring_events_registration\Form\RegistrantForm->save()
call_user_func_array() (Line: 129)
Proposed resolution
Make the email base field required in Registrant::baseFieldDefinitions().
Comments
Comment #2
pfrenssenComment #3
chrisla commentedThis was discussed in https://www.drupal.org/project/recurring_events/issues/3090286 with no resolution.
I propose since email address is required for registering and triggers errors if not present, it makes sense to make it required. More functionality can be added for custom solutions where email is not required.
Comment #4
dhruv.mittal commentedComment #6
dhruv.mittal commentedI have created MR that is solving the issue.
Also I noticed that if once a registration form is generated a error then it's status will be in pending status and when I try to delete the event series related to registrant it produces same error.
And the given MR solves this too. Please review and let me know if any assistance requires.
Thank you.
Comment #7
kul.pratap commentedThe MR resolved the error, so moving this to RTBC.
Attaching a screenshot for reference.
Comment #8
pfrenssenThanks for working on this!
Instead of adding additional code to the form validate handler, let's instead mark the field as required in
Registrant::baseFieldDefinitions()as was proposed in the issue summary.By doing this we will inform Drupal that the field is required. Drupal will then take care of the form validation for us. Also it will do some other helpful things like marking the field as required, support entity validation etc.
We do not need to make any changes to the form, it will all be handled automatically :)
Comment #9
dhruv.mittal commentedPlease review
Comment #10
sagartiwari commentedI am reviewing this issue.
Comment #11
sagartiwari commentedHello, I have verified the issue MR https://git.drupalcode.org/project/recurring_events/-/merge_requests/143... given in comment #9 fixes the issue. It adds a required validation on the Email Address field which prevents the page to encounter the error.
Thanks.
Comment #12
sagartiwari commentedComment #16
plopescMR merged and cherry-picked into 3.0.x. Thank you!