Last active
December 9, 2015 11:00
-
-
Save voidberg/6df7d866e327c4fe788f to your computer and use it in GitHub Desktop.
Displaying entity forms in Drupal 8
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <p>Please register</p> | |
| {{ register_form }} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // 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