Skip to content

Instantly share code, notes, and snippets.

@voidberg
Last active December 9, 2015 11:00
Show Gist options
  • Select an option

  • Save voidberg/6df7d866e327c4fe788f to your computer and use it in GitHub Desktop.

Select an option

Save voidberg/6df7d866e327c4fe788f to your computer and use it in GitHub Desktop.
Displaying entity forms in Drupal 8
<p>Please register</p>
{{ register_form }}
// We do this in the page preprocess function so
// that we can access the variables from page.html.twig.
function theme_preprocess_page(&$variables) {
// Since the register form is an entity form,
// we need to create an entity associated with it
$entity = \Drupal::entityManager()
->getStorage('user')
->create(array());
// Also, an entity can have multiple forms,
// so we need to get the one for the register action.
$formObject = \Drupal::entityManager()
->getFormObject('user', 'register')
->setEntity($entity);
$form = \Drupal::formBuilder()->getForm($formObject);
$variables['register_form'] = $form;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment