Skip to main content

Turn Drupal 8 formbuilderform builder response into HTML?

Source Link
rockstardev
  • 1k
  • 4
  • 23
  • 47

Turn Drupal 8 formbuilder response into HTML?

I have a node type called "competition". I can get a form for it like so:

$values = array('type' => 'competition');
$node = \Drupal::entityTypeManager()
  ->getStorage('node')
  ->create($values);

$form = \Drupal::entityTypeManager()
  ->getFormObject('node', 'default')
  ->setEntity($node);
$form = \Drupal::formBuilder()->getForm($form);

In a controller it's easy enough to return $form and it will be rendered. But I want to do other things with this form so I need it back as HTML. How can I turn $form into fully rendered html?