This is related to How to overrule Craft error messages with custom setError()? but I don't have enough rep to comment on it.
I have a plugin that needs to check if a user is ok to be deleted before doing so. Stopping the delete with $event->performAction = false;
works fine, but I am unable to overwrite the Craft message with my own to tell them why.
The following code demonstrates the problem:
craft()->on('users.onBeforeDeleteUser', function(Event $event){
craft()->userSession->setError("I don't want to delete " . $event->params['user']->username);
$event->performAction = false;
});
If deleting from the edit user page the "Couldn't delete the user" message is shown. I can change setError()
to setNotice()
and it will be displayed alongside the Craft error as a potential workaround, but I'm reporting an error so would like to display it as such. (There is the other workaround of setting the error on a field of the user entry, but in my case the error has nothing to do with a field on the page so this would be misleading.)
If deleting from the users listing page setError()
shows nothing, just the Craft notice "Deleted Users" is shown. This also cannot be overridden with setNotice()
.
Is there a way of overriding the Craft error message or showing my own error message alongside it?