Programmatically Render a Node Edit form with a custom Form Display Mode I'm attempting to make a page for users to edit data for a specific content type, but I only want them to have access to some of the fields not all. To do so I created a custom form display mode for content. I have a custom controller that is meant to display this form with a custom display mode. Here is the code meant to render it.

    public function showCustomForm() {
        $node = \Drupal::entityTypeManager()-&gt;getStorage('node')-&gt;load('123');
        $edit_form = \Drupal::entityTypeManager()-&gt;getFormObject('node', 'my_custom_form_display_mode_id')-&gt;setEntity($node);
        return \Drupal::formBuilder()-&gt;getForm($edit_form);
    }


And I get the error


  Drupal\Component\Plugin\Exception\InvalidPluginDefinitionException:
  The "node" entity type did not specify a
  "my_custom_form_display_mode_id" form class. in
  Drupal\Core\Entity\EntityTypeManager->getFormObject() (line 184 of
  /var/www/mydomain/http/web/core/lib/Drupal/Core/Entity/EntityTypeManager.php).


I was using this How do I load a form with a specific form display (form mode)? as an example. But still had no luck.

How would I programmatically load a node edit form with a custom form display mode?
The error message says you did not specify a form class, but what it really wants to say is, that you did not specify a form operation with the name of the form mode:

mymodule.module:

function mymodule_entity_type_build(array &amp;$entity_types) {
  $entity_types['node']-&gt;setFormClass('my_custom_form_display_mode_id', 'Drupal\node\NodeForm');
}


The form operation needs a form class. This can be the same as for default, which you find in the handlers section of the annotations in the Node class.