how to render content type's fields in Custom Module Form I'm new to Drupal 8 and I'm trying to create a form that allow to fetch my content types hierarchy and show its fields using ajax callback, but unfortunately none of the fields shows up eventhough the ajax works fine and callback function correctly fired?
The Fields Types in my ContentType is {body:text_with_summary, price:decimal, title:string}
As I Tried with debugging it seems that my code cannot define those types as form field types

here is my code in MyForm.php File:

public function level3SelectedCallback(array &amp;$form, FormStateInterface $form_state) {
    $ajax_response = new AjaxResponse();
    $fields = MyController::contentTypeFields('MY_VOC');

    foreach ($fields as $field){
        $name = $field-&gt;id();
        $label = $field-&gt;label();
        $type = $field-&gt;getType();
        $desc = $field-&gt;getDescription();
        $form['fields_wrapper']['field_'.$label] = array(
            '#type' =&gt; $type,
            '#description' =&gt; $desc,
            //'#options' =&gt; '',
            '#attributes' =&gt; array(
                'class' =&gt; array(
                    'myField'
                ),
            ),
            );
        $ajax_response-&gt;addCommand(new HtmlCommand('#fields-wrapper', $form['fields_wrapper']['field_'.$label]));

    }

    $ajax_response-&gt;addCommand(new InvokeCommand('#fields-wrapper', 'change'));
    $form_state-&gt;setRebuild(True); 

    return $ajax_response;
}


My Controller Function is:

static function contentTypeFieldsAsFields($contentType) {
    // Get the definitions
    $fields = array_filter(
            \Drupal::service('entity.manager')-&gt;getFieldDefinitions('node', $contentType), function ($field_definition) {
                return $field_definition instanceof \Drupal\field\Entity\FieldConfig;
            }
    );
    return $fields;
}
To get an empty form of a content type you would use code like this:

$node = \Drupal\node\Entity\Node::create(['type' =&gt; 'page']);
$form = \Drupal::service('entity.form_builder')-&gt;getForm($node);


To open this form with ajax, put the form in a controller:

public function contenttypeform(NodeTypeInterface $node_type) {
    $node = $this-&gt;entityTypeManager()-&gt;getStorage('node')-&gt;create([
      'type' =&gt; $node_type-&gt;id(),
    ]);
    return $this-&gt;entityFormBuilder()-&gt;getForm($node);
  }


Configure a route for this controller and open the form in an ajax modal like this example from ConfigSync.php:

$links['view_diff'] = array(
            '#type' =&gt; 'link',
            'title' =&gt; $this-&gt;t('View differences'),
            'url' =&gt; Url::fromRoute($route_name, $route_options),
            'attributes' =&gt; array(
              'class' =&gt; array('use-ajax'),
              'data-dialog-type' =&gt; 'modal',
              'data-dialog-options' =&gt; json_encode(array(
                'width' =&gt; 700
              )),
            ),
          );