The following link:

https://api.drupal.org/api/drupal/core%21core.api.php/group/form_api/8.2.x

says the following in part.

Retrieving and displaying forms

\Drupal::formBuilder()->getForm() should be used to handle retrieving, processing, and displaying a rendered HTML form. Given the ExampleForm defined above, \Drupal::formBuilder()->getForm('Drupal\mymodule\Form\ExampleForm') would return the rendered HTML of the form defined by ExampleForm::buildForm(), or call the validateForm() and submitForm(), methods depending on the current processing state.

I used this pattern and found that formBuilder->getForm returns a complex data structure that I believe is known as a Form Array. I believe this documentation needs to be updated as a result. The following page seems to agree with my results:

https://api.drupal.org/api/drupal/core%21lib%21Drupal%21Core%21Form%21Fo...

I need to be able to place a form in an arbitrary place in a Block. I was hoping formBuilder->getForm would allow this -- but this does not seem to be the case.

Comments

Greg Sims created an issue.

eojthebrave’s picture

That's correct. The data returned from FormBuilder::getForm() is a renderable array. Depending on what exactly you're trying to do you have a few options for how to deal with it.

It sounds like you're creating a custom block plugin. If so, you should be able to return a renderable array from the plugin's ::build() method. See the documentation here https://api.drupal.org/api/drupal/core%21lib%21Drupal%21Core%21Block%21B...

Alternatively, you can use drupal_render() or the 'renderer' service, to convert the renderable array from the FormBuilder to a string of HTML. The method above, returning a renderable array, is generally preferred.