D8 render a contact form from theme preprocess I want to render a form in a node view. I made an entity reference to a contact form, then in the preprocess_node I'm trying to get the render array of the contact form.

function mysupertheme_preprocess_node(&amp;$variables) {
  $node = $variables['node'];

  if ($node-&gt;getType() == 'mynodetype') {
    if (!empty($node-&gt;field_mynodetype_form-&gt;referencedEntities())) {
      $contact_form = $node-&gt;field_mynodetype_form-&gt;referencedEntities()[0];
      $message = \Drupal::entityManager()
      -&gt;getStorage('contact_message')
      -&gt;create(array(
        'contact_form' =&gt; $contact_form-&gt;id(),
      ));

      //$form = \Drupal::entityFormBuilder()-&gt;getForm($message);
    };
  }
}


I don't know how to call entityFormBuilder in preprocess. Is this the right way to do this ? How can I display a choosen contact form in a node ?

Thanks
Your code will work when this patch is implemented:

Add a view builder for contact_form