How to expand NodeForm so new argument can passed to it I have a content type called service request, which have some conditional fields that each might appear or disappear based on an other field value called service type.
I have used conditional field and they work just right but for better user experience I want node form to be called using one of the service types.
so I tried to follow this instructions provided by Jaypan to extend NodeForm, but when overriding form function of NodeForm, it leads to Error: Call to a member function getEntityTypeId() on null in Drupal\Core\Entity\EntityForm-&gt;getBaseFormId()
this is how I used to create $form:
class ServiceBuilderForm extends NodeForm {
  /**
   * {@inheritdoc}
   */
  public function form(array $form, FormStateInterface $form_state, $serviceType = NULL) {
    // Added as a fallback in case a developer uses this form without passing
    // $someId:
    if (is_null($serviceType)) {
      $form = [
        '#prefix' =&gt; '&lt;p class=&quot;error&quot;&gt;',
        '#suffix' =&gt; '&lt;/p&gt;',
        '#markup' =&gt; $this-&gt;t('Form is missing Service Type which is required'),
      ];
    }
    else {
      $form = parent::form($form, $form_state);
      // Do something with $form and $some_id
    }

    return $form;
  }
}

and in my Controller I have get my form using:
$form = \Drupal::formBuilder()-&gt;getForm('\Drupal\{my_module}\Form\ServiceFormBuilder', $serviceType);
After you have integrated the form class in the entity type as form mode
function mymodule_entity_type_build(array &amp;$entity_types) {
  $entity_types['node']-&gt;setFormClass('service', 'Drupal\mymodule\Form\ServiceBuilderForm');
}

and invoked the node form in a controller
$form = $this-&gt;entityFormBuilder()-&gt;getForm($node, 'service');

or without controller directly in a route:
_entity_form: 'node.service'

the entity including the field data is passed to your form
class ServiceBuilderForm extends NodeForm {
  /**
   * {@inheritdoc}
   */
  public function form(array $form, FormStateInterface $form_state) {
    $node = $this-&gt;entity;
    if ($node-&gt;getType() == 'service_request') {
      $field_value = $node-&gt;field_service_type-&gt;value;
  

and you avoid the error from your question that the entity is null.