How do I add a node field widget to a custom form? I added a number of fields to a node content type in Drupal 8. I want to create a custom form and add the field widget form (the one used during node creation) to this form.
How can I achieve this?
Answering my own question, I ended up using the following:
&lt;?php
//Create an empty representative entity
$node = \Drupal::service('entity_type.manager')-&gt;getStorage('node')-&gt;create(array(
                'type' =&gt; 'article'
            )
        );

//Get the EntityFormDisplay (i.e. the default Form Display) of this content type
$entity_form_display = \Drupal::service('entity_type.manager')-&gt;getStorage('entity_form_display')
                                        -&gt;load('node.article.default');

$form['#parents'] = []; // Mandatory, otherwise the widget class throws an error

//Get the body field widget and add it to the form
if ($widget = $entity_form_display-&gt;getRenderer('body')) { //Returns the widget class
  $items = $node-&gt;get('body'); //Returns the FieldItemsList interface
  $items-&gt;filterEmptyItems();
  $form['body'] = $widget-&gt;form($items, $form, $form_state); //Builds the widget form and attach it to your form
  $form['body']['#access'] = $items-&gt;access('edit');
}

see EntityFormDisplay::buildForm