On my site, users sign up by submitting their email and name to a user registration form. They will get an email with a link that will allow them to complete the rest of the sign up process, like setting a password. The issue I am having is that when a new user signs up, two messages pop-up. The first message says that a link has been sent to their email with further instructions, which is what I want. However, The second message, which is hidden behind the first, says the email address is already taken. Once a user closes the first message they will see the second message. The second error message is misleading and I would like only the first error message to display when users sign up.

 if($path == '/user/login') {
    /***** user sign-up ******/
    $entity = \Drupal::entityManager()->getStorage('user')->create(array());

    $formObject = \Drupal::entityManager()->getFormObject('user', 'register')->setEntity($entity);

    $form = \Drupal::formBuilder()->getForm($formObject);
    $variables['register_form'] = $form;

The code above is how I am getting the registration form to display on page--user--login.html.twig (by calling register_form in the twig template). This is in the .theme file in the mytheme_preprocess hook.

The login/signup page path is /user/login. (so both the user registration form and user login form is on this page. Both have submit buttons)

  • I wonder if this isn't solved by maybe rendering the form before assigning it to the variable: $variables['register_form'] = \Drupal::service('renderer')->renderRoot($form); – Jaypan Mar 23 at 20:21
  • I get the following error: LogicException: A stray renderRoot() invocation is causing bubbling of attached assets to break. in Drupal\Core\Render\Renderer->renderRoot(). I did a quick google and changed renderRoot($form) to render($form, false) but this caused the following error: Fatal error: Allowed memory size of 268435456 bytes exhausted (tried to allocate 20480 bytes) in /app/core/lib/Drupal/Core/Render/Element/RenderElement.php on line 260 – gitclapped Mar 23 at 21:37
  • should also mention with my previous comment that if I change the memory limit to -1, I get a timeout error – gitclapped Mar 23 at 22:31
  • That wasn't the solution then. Sorry! – Jaypan Mar 24 at 6:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.