I didn’t find this info written, and the logic of function getEventMap in the core is fuzzy, so I post "how-to" and at the same time ask if there’s another way..
Events+Plugins are great for activity stream, notification,etc.. But, for example in Quip commenting addon, there are no built-in events. This is a simple example for "OnQuipCommentDelete", but works the same for
whatever...
1.Add this code last thing before the return in:
core\components\quip\processors\web\comment\remove.php
/* invoke OnQuipCommentDelete event */
$modx->invokeEvent('OnQuipCommentDelete', array (
'comment' => &$comment
));
2. I manually added this to the database:
INSERT INTO `modx_system_eventnames` (`id`, `name`, `service`, `groupname`) VALUES (NULL, 'OnQuipCommentDelete', '1', '');
*Note: the "service=1" and groupname="" logic came from reading this
weird line in
core\model\modx\modx.class.php, function getEventMap.
$service= "ev.`service` IN (1,3,4,5,6) AND (ev.`groupname` = '' OR ev.`groupname` = 'RichText Editor' OR ev.`groupname` = 'modUser') AND";
3. Create the plugin:
name: sample
System Events: OnQuipCommentDelete
code:
<?php
$comment =& $scriptProperties['comment'];
$modx->sendRedirect($modx->makeUrl($comment->get('thread')));
?>
in the above example, after comment deleted successfuly - redirect to page (where thread holds the document id, future Quip will probably use the parent as id..)
Now, the question:
I saw in Discuss svn you used hooks: $modx->hooks->load(...), added to
deprecated-feeling of getEventmap, I get a feeling custom events should follow the discuss’s hooks-way?
If not - what’s up with this service number, and why not allow custom groupname ("Quip").
Thanks.