entities – 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 DrupalCoreEntityEntityForm->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' => '<p class="error">',
        '#suffix' => '</p>',
        '#markup' => $this->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()->getForm('Drupal{my_module}FormServiceFormBuilder', $serviceType);

Default Expand Media Categories | NulledTeam UnderGround

Sorry, building a ‘template modification add-on’ to release is currently beyond me.. :X3:

For now, you can either edit the template xfmg_category_list_macros directly, or set up your own template modification.

View attachment 19532

View attachment 19533

Find (2 instances):