Overriding an entity add/edit form through alterroute I want to create my own version of the add/edit form for an entity defined in contrib module (drupal_commerce). I assumed i'd be able to adapt the example here http://www.foreach.be/blog/how-manipulate-forms-drupal-8 to alter route for entity forms. However i am getting the following when i try to load edit


  Fatal error: Call to a member function getEntityTypeId() on a non-object in C:\xampp\htdocs\tocyn\core\lib\Drupal\Core\Entity\EntityForm.php on line 82


My route subscriber looks like:

    if ($route = $collection-&gt;get('entity.commerce_product.edit_form') ) {
        $defs = $route-&gt;getDefaults();
        $route-&gt;setDefault('_form', '\Drupal\mymod\Form\EventForm');
    }


And my new form:

class EventForm extends Drupal\commerce_product\Form\ProductForm
{
   public function buildForm(array $form, FormStateInterface $form_state)
   {

      // doing nothing much here
      return $form;
   }
}


Do i need to do something with _entity_form also??
Grateful for any feedback
Mathew
Alternatively, you can use hook_entity_type_alter() to override the default form handler classes. It would be something like:

/**
 * Implements hook_entity_type_alter().
 */
function mymod_entity_type_alter(array &amp;$entity_types){
  $entity_types['commerce_product']-&gt;setHandlerClass('form', array(
    'edit' =&gt; 'Drupal\mymod\Form\EventForm'
  ));
}