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?
hook_menu_alter()
, but there is still a way to alter routes another module is providing.