Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save vyspiansky/9bb2114d31bb0e68ca40aa29b3e89153 to your computer and use it in GitHub Desktop.
Save vyspiansky/9bb2114d31bb0e68ca40aa29b3e89153 to your computer and use it in GitHub Desktop.
Extend a standard user registration form using classes in Drupal 10

To extend the standard user registration form, use

namespace Drupal\your_module\Form;

use Drupal\Core\Form\FormStateInterface;
use Drupal\user\RegisterForm;

class YourRegisterForm extends RegisterForm {
  public function buildForm(array $form, FormStateInterface $form_state) {
    $form = parent::buildForm($form, $form_state);

    // Add your custom fields here.

    return $form;
  }
}
function your_module_entity_type_alter(array &$entity_types) {
  $entity_types['user']->setFormClass('register', 'Drupal\your_module\Form\YourRegisterForm');
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment