how to extend FormBuilder::processForm from multiple API endpoints in one class I'm trying to consolidate my form processing by entity_type, without rebuilding the forms (just using the default forms provided by Drupal. 

I have dynamic routes pointing to a _controller::method. I've tried:


A. \Drupal::service('entity.form_builder')-&gt;getForm($group_content, 'edit', $data) but this just returns a render array, no instance.
B. \Drupal::formBuilder()-&gt;getForm('\Drupal\group\Entity\Form\GroupContentForm') but this is the wrong class path and i can't figure out how I could reference any entity:bundle:id by any pattern (i've tried many)
C. Changed the route to use _form or _entity_form extending FormBase (instead of a controller), but it seems these require the buildForm method to defined the form's full field list (which defeats the purpose of my question).


What is the best approach to expose edit/add/delete process handlers for multiple bundles / entity_type in a single class?
A. EntityFormBulder::getForm is just a shortcut for instantiating the form object, injecting the entity and building the render array. You can split this up:

  public function getForm(EntityInterface $entity, $operation = 'default', array $form_state_additions = []) {
    $form_object = $this-&gt;entityTypeManager-&gt;getFormObject($entity-&gt;getEntityTypeId(), $operation);
    $form_object-&gt;setEntity($entity);

    $form_state = (new FormState())-&gt;setFormState($form_state_additions);
    return $this-&gt;formBuilder-&gt;buildForm($form_object, $form_state);
  }


B. You have to inject the entity before you can build an entity form, see the steps above.

C. _entity_form is for integrating an entity form in a route, then the route parameter is upcasted and injected into the form automatically, see How to Inject entity object in EntityForm

The best approach is C. (standard pattern) and refactor the OOP code.

BTW if you don't find a OOP solution or if it is too complicated then you could simply add a custom process callback to $form['#process'] in a form alter hook to all or specific entity forms.