node_delete_confirm_submit() and hook_node_delete() Still getting my head around Drupal 8 after using Drupal 7 for so long. I want to override (alter) the node delete action. Now in Drupal 7 I would have used  node_delete_confirm_submit() and hook_node_delete() or similar such as using hook_form_alter and changing the submit function.

In Drupal 8 this has partly changed. I can still use hook_node_delete(), but there is no node_delete_confirm_submit() which was deprecated in favor of \Drupal\Core\Form\ConfirmFormBase. Rather than try and create a hack I would like to learn the proper way I should be doing this.

I have tried to use ConfirmFormBase. I have a src/Form/DeleteXXXConfirm.php file.

namespace Drupal\XXX\Form;

use Drupal\Core\Form\ConfirmFormBase;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Url;

class DeleteXXXConfirm extends ConfirmFormBase {

   ... code here for confirm and delete ...

}


Since I want to override node/nid/delete, I assumed the routing file would look something like this.

XXX.delete:
  path: '/node/{id}/delete'
  defaults:
    _form: '\Drupal\XXX\Form\DeleteXXXConfirm'
    _title: 'Confirm Deletion'
  requirements:
    _permission: 'administer site configuration'
    id: ^\d+$


This doesn't appear to work, do I need a Controller? Or am I totally barking up the wrong tree? I am obviously misunderstanding something. Can anyone point me in the right direction?
I've found inspecting the routes availble and then working back to the controller to be a super helpful way to understand how to override things.

You will need Drupal console installed.

For example run 

drupal router:debug | grep node | grep delete


This will list all routes, and then filter only ones with node in and then filter only ones with delete in. 

You should then see the route you are interested in (/node/{node}/delete) is called entity.node.delete_form

Now you can debug just that specific route:

drupal router:debug entity.node.delete_form


This will show you that the form for this route is called node.delete. If however there was a method and a controller for the route is would show you exactly what the callback is.

To change the entity.node.delete_form route to use your own callback you can use the new method of doing menu_alter.

However if you want to keep the same node delete form and just change the submit handler then you can still use hook_form_alter to change this.