on_page_delete not firing

Permalink
I was hoping to find a quick solution to this problem somewhere in the forum but with no luck so far. I'm certain you concrete5 gurus can help me ;)

The problem is that the on_page_delete event does not fire - the function is not executed. I have tried using Log::addEntry('message') but the log remains untouched.

The site is set up correctly with site.php containing the ENABLE_APPLICATION_EVENTS set to true and site_events.php including:

Events::extendPageType('my_invest', 'on_page_delete');

I have also tried Events::extend('on_page_delete', 'MyInvest', 'on_page_delete', 'models/my_invest.php') but with no luck.

It just doesn't read or find the handler.

This is were I get really confused...I currently have another event handler for the on_composer_publish event which works spot on, and it uses the same page type. I've tried possibly everything (?), and I would like to avoid overriding core files to make this work.

Any ideas/solutions/fixes??

Thanks!

yourzoneit
 
yourzoneit replied on at Permalink Reply
yourzoneit
OK, problem solved.

Basically, with 5.6.0.2 at least, deleted pages are not deleted immediately but sent to the Trash. This means that the on_page_move is triggered rather than the on_page_delete.

For those who bumped into the same problem, either disable the Trash by inserting this line to your site.php:

/* this will delete pages permanently from your website instead of moving under Trash, and will also trigger the on_page_delete */
define('ENABLE_TRASH_CAN', false);



or add a new event handler in the site_events.php file.

Events::extendPageType('page_type_handle', 'on_page_move');
Events::extendPageType('page_type_handle', 'on_page_delete');


Remember to define them functions in the page type controller. Obviously, in the on_page_move function, you may want to create a condition that verifies if the page was sent to the Trash Can before triggering the on_page_delete.

Keep both just in case you decide to disable TRASH_CAN in the future.

Hope this makes sense.

Cheers