G2 Module : Problem with Register events and handlers

dipsaggarwal

Joined: 2007-08-22
Posts: 11
Posted: Thu, 2007-08-30 10:25

I have G2 User Activity Log module that is installing good.

However, I am trying to registerListeners() and writing a handler(). The code I have
written for the purpose is below and it is not doing anything.

in module.inc :

function registerEventListeners() {

GalleryCoreApi::requireOnce('modules/useractivitylog/classes/UserActivityLogHelper.class');
$listener = new UserActivityLogHelper();
GalleryCoreApi::registerEventListener('GalleryEntity::save', $listener);
GalleryCoreApi::registerEventListener('GalleryEntity::delete', $listener);
}

in classes/UserActivityLogHelper.class :

function handleEvent($event) {

$valid_event = false;
if ($event->getEventName() == 'GalleryEntity::save') {
$entity = $event->getEntity();
if ($entity->getEntityType() == 'GalleryAlbumItem') {
// do something when user saves album
}
}

return array(null, null);
}

I think my handler is not even getting called in any event and definitely not when I
add an album.

Thanks,

Deepak

 
valiant

Joined: 2003-01-04
Posts: 32509
Posted: Thu, 2007-08-30 10:39

- don't forget to declare your registerEventListener method in the module constructor
$this->setCallbacks('registerEventListeners');
- reinstall the module

--------------
Documentation: Support / Troubleshooting | Installation, Upgrade, Configuration and Usage

 
dipsaggarwal

Joined: 2007-08-22
Posts: 11
Posted: Fri, 2007-08-31 04:54

Thanks that certainly did the job.

 
Charles08

Joined: 2008-02-22
Posts: 25
Posted: Wed, 2008-04-23 22:24

I know this post is a bit old but I found it looking for examples on how to use the registerEventListeners and this is a great example of how to do it.
Of course this will change in 2.3 as it will no longer be used. Later I will post an example of how to use the new way to listen to events.