0

We are using a plugin that has created its own record for storing private messages. When deleting a message, it's calling the delete() method on an instance of the record, which appears to be using the CActiveRecord's implementation of delete.

In CActiveRecord::delete(), it has a $this->afterDelete() method, which looks like it should be raising an onAfterDelete event, but I haven't had any luck hooking into it.

I've tried craft()->on('pluginhandle_messageRecord.onAfterDelete', ...) and craft()->on('cActiveRecord.onAfterDelete', ...), but neither gets triggered.

Does anyone know the correct syntax for hooking into this event for this specific custom record?

Thanks!

1 Answer 1

1

Because that's a Yii event, it doesn't follow the same component.eventName syntax that the other Craft events use and you can't use craft->on() to register to listen to it.

Completely untested, but you should be able to use the traditional Yii method, though. Something like this:

$myRecord->onAfterDelete = function (Event $event) {
    // Do your thing.
};
4
  • It's good to know that craft()->on() won't work, otherwise I probably would've gone crazy trying different things. So essentially the change would need to be made inside the plugin itself?
    – John O
    Commented Oct 21, 2015 at 17:13
  • Yeah, I wasn't clear on whether this one in the context of two plugins or just one.
    – Brad Bell
    Commented Oct 21, 2015 at 17:54
  • The delete is occurring within a 3rd party plugin, and I want to be able to tie into that using a plugin we are developing. It sounds like that wouldn't be possible, since the change needs to be made directly in the 3rd party plugin.
    – John O
    Commented Oct 21, 2015 at 18:12
  • Yeah, I think you'd need to fork the 3rd party plugin (or make a pull request) to expose that deletion for your plugin to use.
    – Brad Bell
    Commented Oct 21, 2015 at 18:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.