How can I get the Register form on the front page? I've managed to create a new theme, customize the front page pretty much how I wanted it, and I've encountered a problem.

I need to get the register form (create new account) in a pop-up on the front page.

After following the instructions from Form API in Drupal 8:

    &lt;?php

/**
* @file
* Functions to support theming in the themename theme.
*/

use Drupal\Core\Form\FormBase;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Component\Utility\UrlHelper;

/**
* Implements hook_preprocess_HOOK() for HTML document templates.
*/

function themename_preprocess_html(&amp;$variables) {

$form = \Drupal::formBuilder()-&gt;getForm('Drupal\user\register');

return $form;
}


I can't figure out what I'm doing wrong, because I get an error saying that is not a valid form. I have also tried using the form id as a parameter, still no valid form.

Could anyone please help? I could use a working example.
The correct form id shoud be Drupal\user\RegisterForm. However, because the register form is attached to an entity, you can't use getForm directly. You need to create an entity and then get the register form for that entity.

The role of the preprocess function is to add / modify / delete template variables via the $variables parameter, so you need to add the form to that array rather than return it.

Something like this should work:

function themename_preprocess_page(&amp;$variables) {  
  $entity = \Drupal::entityManager()
    -&gt;getStorage('user')
    -&gt;create(array());

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

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


Now you should be able to print the form via {{ login_form }} in the page.html.twig template.