I need to run checks before allowing a user to delete a category. I have added the following code to my main plugin class:
craft()->on('categories.onBeforeDeleteCategory', function(Event $event) {
$event->performAction = false;
});
This is just to test it. I expect this to cause any category delete functions to fail because I'm explicitly setting the event perform action property to false.
There are two problems:
No. 1 - This code only runs when I click into the category and then press the delete button. If you do it from the action menu in the category list this event is not even fired. This seems like a bug to me.
No. 2 - This code, even when executed, does not prevent the category from being deleted. Even though I set $event->performAction = false
it still just deletes the category.
Any ideas?
EDIT:
I did some sleuthing regarding #1 and I found out that I have to call the event like this:
craft()->on('elements.onBeforeDeleteElements', function(Event $event) {
$event->performAction = false;
});
However I'm still running into #2 on both instances where setting performAction to false does not prevent the action from completing... :(
Edit 2 It looks like there is no condition for performAction after the event is fired so there appears to be no way to stop a delete event via an event. Is this the case?