How to extend a specific node type form? I am searching a way to overwrite the NodeForm to get a class per bundle.

Actually EntityForm manages the form for all entities.
NodeForm extends it and manages the forms for all nodes.

I wrote a CustomNodeForm replacing NodeForm behaviour for all nodes.

/**
 * Implements hook_entity_type_build().
 */
function ftvisi_main_entity_type_build(array &amp;$entity_types) {
  $entity_types['node']-&gt;setFormClass('default', CustomNodeForm::class);
}


Now I'd like to get a class per bundle extending that CustomNodeForm but I feel like I am not able to do it.

CustomNodeForm might instantiate a form for each bundle - but I don't like that approach and we still just have one constructor which can leads to problems such as:

"OK my first bundle form needs this service, and my second bundle form needs another one, should I inject the full container itself and then use services on the fly ?" => Pretty bad idea, I know.

Anyway, if CustomNodeForm instantiates other classes itself, it will be hard to mock and test. So I definitively don't like that approach.

I then thought about using the form modes, but same problem: a form mode can be used on any node type, so we still don't have a class per bundle and we still have only one constructor for all forms using that form mode.

Any idea to help?
AFAIK forms are tied to operations at entity-type level, so you don't have any hook to only alter the form for a particular bundle. Since what you want is to inject certain services for a given bundle what you can do is to implement a chain of responsability pattern through service collectors. This allows you to inject only the service collector to your form and delegate to the collection to evaluate which service should apply for your given bundle. And finally the resolved service is the one that would concentrate the responsability. I could provide you with a deep example but could take some time, let me know if a code sample still needed.

UPDATE

This will be the solution in a near future, since sub-classing is the feature you are referring.