How do I load the node create or edit form? To load the login form I am using the following code.

$form = \Drupal::formBuilder()-&gt;getForm('Drupal\user\Form\UserLoginForm');


I would like to load the form to create or edit a node. How can I achieve this?
Copying partially from an answer that I gave here: How to alter $form_state before render a form?

To get an add form, you can have to do something like this:

$values = array('type' =&gt; $node_type);

$node = \Drupal::entityTypeManager()
  -&gt;getStorage('node')
  -&gt;create($values);

$form = \Drupal::entityTypeManager()
  -&gt;getFormObject('node', 'default')
  -&gt;setEntity($node);
return \Drupal::formBuilder()-&gt;getForm($form);


Edit: Somehow I missed that you said edit. You do exactly the same then, except that you don't create a new $node, you load the one you want to edit and then use that.

As written there, this is based on the entityblock_form module, so if you need this in a block, you can also just use that module.