Gallery:按事件的外观主题覆盖
来自站长百科
按事件的外观主题覆盖[ ]
如果每相册外观主题和外观主题设定不够灵活以致无法满足你的需要的话,你可以注册一个事件侦听器来覆盖外观主题,该外观主题应被用于显示当前视图(页面)。
举例[ ]
定义一个事件侦听器(Event Listener)[ ]
/*定义一个事件侦听器来决定使用那个外观主题*/
class MyThemeEventListener /* extends GalleryEventListener */ {
function handleEvent($event) {
global $gallery;
$data = $event->getData();
$item = $event->getEntity();
if ($gallery->isEmbedded() && $data['viewType'] == VIEW_TYPE_SHOW_ITEM) {
$themeId = 'nzdi';
} else if {$data['viewType'] == VIEW_TYPE_ADMIN) {
$themeId = 'matrix';
} else {
// 让其对此请求使用已配置的外观主题
$themeId = null;
}
return array(null, array('themeId' => $themeId));
}
}
注册事件侦听器[ ]
在模块中[ ]
/* 在module.inc中 */
function performFactoryRegistrations() {
return GalleryCoreApi::registerFactoryImplementation('GalleryEventListener',
'MyThemeEventListener ', 'mymoduleid', 'modules/mymoduleid/classes/MyThemeEventListener.class', 'mymoduleid',
array('Gallery::LoadThemeAndParameters'));
}
对于整合[ ]
/* 在整合代码中*/
$ret = GalleryEmbed::init(...);
...
/* 路径仅当时间侦听器(class MyThemeEventListener)尚未定义时相关。*/
$ret = GalleryCoreApi::registerFactoryImplementationForRequest('GalleryEventListener',
'MyThemeEventListener ', 'myintegration', '/../relative/path/to/my/integration/integrationCode.php', 'myintegration',
array('Gallery::LoadThemeAndParameters'));
...
$data = GalleryEmbed::handleRequest();
...
注意还有稍简单但欠灵活的备用方法:
/*在整合代码中*/
$ret = GalleryEmbed::init(...);
...
$ret = GalleryEmbed::setThemeForRequest('siriux')
...
$data = GalleryEmbed::handleRequest();
...
Gallery::LoadThemeAndParameters 事件定义[ ]
在核心API 7.40 / 嵌入API 1.3中介绍了此事件。
事件数据[ ]
- 'viewType':为其中之一:VIEW_TYPE_MODULE|VIEW_TYPE_SHOW_ITEM|VIEW_TYPE_ADMIN|VIEW_TYPE_ERROR (常量)
- 'viewName':具有Gallery视图名称的格式(与GalleryUrlGenerator::generateUrl()中的'视图'格式相同如,'core.ShowItem')。
事件实体[ ]
- $event->getEntity()为当前页面返回null或GalleryItem。
返回值[ ]
返回值是与下列键相关联的一个数组:
- 'themeId' 字串 – 此请求所用的外观主题的外观主题id。若要让Gallery使用已配置的外观主题而不是某个覆盖的话,就忽略此键或将其值设置为null。
- 'params'数组(可选)- 外观主题参量,也允许覆盖外观主题参量。如未被定义,特定外观主题的默认外观主题参量将被使用;反之参量应为无尽的。
外观主题参量的覆盖[ ]
覆盖外观主题参量,让用户对外观主题进行配置使其用作override是有意义的。 参看一下keyalbum模块(modules/keyalbum/KeywordAlbumSiteAdmin.inc)来看看某外观主题设定页面是如何显示和处理的,以及设定是如何被存储的。