Commit 534f901b authored by profix898's avatar profix898

- task: establish event listener infrastructure

parent cc868a6c
<?php
// $Id: $
/**
* Class G2DrupalHelper {}.
*/
class G2DrupalHelper {
function registerEventListeners($listeners) {
foreach ($listeners as $listener) {
// Default path to event listener class
if (!isset($listener['path'])) {
$listener['path'] = drupal_get_path('module', 'gallery') .'/G2DrupalHelper.class';
}
// Store event parameters
$listener['events'] = is_array($listener['events']) ? $listener['events'] : array($listener['events']);
foreach ($listener['events'] as $event) {
G2DrupalHelper::eventParams($event, $listener['params']);
}
// Register event listener
$ret = GalleryCoreApi::registerFactoryImplementationForRequest(
'GalleryEventListener',
$listener['class'],
'G2Drupal',
$listener['path'],
'G2Drupal',
$listener['events']
);
// G2 register call failed
if ($ret) {
return $ret;
}
}
return false;
}
function eventParams($event, $params = NULL) {
static $storage = NULL;
// Save event params
if (isset($params)) {
$storage[$event] = $params;
}
// Get event params
if (isset($storage[$event])) {
return $storage[$event];
}
return array();
}
}
/**
* Class G2DrupalSimpleThemeEventListener {}.
*/
class G2DrupalSimpleThemeEventListener /* extends GalleryEventListener */ {
function handleEvent($event) {
$eventParams = G2DrupalHelper::eventParams($event->getEventName());
if (count($eventParams)) {
return array(null, $eventParams);
}
return array(null, null);
}
}
/**
* Class G2DrupalPageCacheEventListener {}.
*/
class G2DrupalPageCacheEventListener /* extends GalleryEventListener */ {
function handleEvent($event) {
// Clear the page cache, so that the updated G2 item shows correctly
cache_clear_all();
return array(null, null);
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment