I'm trying to extend registration form programatically to add an additional field. I was following an example from Extend _form in Drupal 8
- I created a new service that will redirect to the new form.
- I created a route subscriber to that will return the new form.
- I created a form class that will extend the form.
It works for the user login form but wont work on user registration form because it is an _entity_form
and I guess it should be treated differently. I changed the router subscriber to match registration form but i get this error.
Call to a member function getEntityTypeId() on null.
if ($route = $collection->get('user.register')) {$route->setDefault('_entity_form', '\Drupal\form_overwrite\Form\NewUserLoginForm');
Can anyone suggest please what's the right way to extend this form?
I tried with the all known hook_form_alter
but even like that I'm not sure how to save the new field content in the configuration files.