drupal-themingdrupal-formsdrupal-8

How can I get the Register form on the front page in Drupal 8?


I've been trying to get the create account form (register form) in a pop-up on the front page, without any success.

Can anybody here help me out with an example that works?

I've tried adapting examples from Drupal 7 but couldn't get them to work, I've tried to make a custom form but it didn't work, I've tried installing modules that could handle this but they also didn't work.

The last attempt I've made to resolve this problem was:

<?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(&$variables) {

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

return $form;
}

Any help would be greatly appreciated. Thank you!


Solution

  • you can use this module: https://www.drupal.org/project/formblock which exposes some additional forms as blocks (like the user registration, new password, contact, etc..). So after you install it you can just configure the block to appear only on the front page. The registration block will not be available for authenticated users or if the anonymous users are not allowed to create new accounts.

    However, you will also have to apply this patch https://www.drupal.org/node/2570221 (if it will not be already committed by the time you check it) if you use the latest Drupal8 stable version, otherwise you will get a fatal error.