Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Try Vanilla Forums Cloud product

How to capture Vanilla Model Events in custom addon?

neelkanthneelkanth New
edited September 8 in Development

Hello,

I want to handle BeforeSaveDiscussion event of DiscussionModel in a custom plugin. So I created a plugin with below code and enabled it.

class MyPlugin extends Gdn_Plugin
{

public function __construct()
{
    parent::__construct();
}

public function DiscussionModel_BeforeSaveDiscussion_Handler($sender, $args)
{
    echo "<pre>";
    die("hello");
}

}

But it looks like this event is not getting called because discussion gets saved but "hello" is not printed. I have checked the browser's console.

I borrowed the above from the QnA plugin (plugins/QnA/class.qna.plugin.php):

public function DiscussionModel_BeforeSaveDiscussion_Handler($Sender, $Args)
{
$Sender->Validation->ApplyRule('Type', 'Required', T('Choose whether you want to ask a question or start a discussion.'));

  $Post =& $Args['FormPostValues'];
  if ($Args['Insert'] && GetValue('Type', $Post) == 'Question') {
     $Post['QnA'] = 'Unanswered';
  }

}

Can anyone please help me out here. I might be missing a very small thing here.

Thanks.

Comments

Sign In or Register to comment.