将默认成员标签更改为elgg中的常用标签

时间:2016-09-05 16:24:59

标签: php plugins elgg

我在elgg中编写了一个插件,将elgg members的默认标签更改为成员列表中的热门而非newest。但有一个问题。当我将默认标签设置为popular时,newest标签不再有效。 这是我的start.php文件:

<?php
elgg_register_event_handler('init', 'system', 'plug_test_init');

function plug_test_init(){

    elgg_unregister_page_handler('members');
    elgg_register_page_handler('members', 'set_popular_as_default');

}   
function set_popular_as_default($page) {
    if (empty($page[0])) {
        $page[0] = 'popular';
    }
    if ($page[0] == 'search') {
        echo elgg_view_resource('members/search');
    } else {
        echo elgg_view_resource('members/index', [
            'page' => $page[0],
        ]);
    }
    return true;
}

1 个答案:

答案 0 :(得分:0)

感谢iionly中的elgg community,在this discussion中,使用成员钩子解决了问题:

<?php
elgg_register_event_handler('init', 'system', 'plug_test_init');

function plug_test_init(){
    elgg_unregister_plugin_hook_handler('members:config', 'tabs', "members_nav_newest");
    elgg_register_plugin_hook_handler('members:config', 'tabs', "my_members_nav_newest");
    elgg_unregister_page_handler('members');
    elgg_register_page_handler('members', 'set_popular_as_default');

}   
function set_popular_as_default($page) {
    if (empty($page[0])) {
        $page[0] = 'popular';
    }
    if ($page[0] == 'search') {
        echo elgg_view_resource('members/search');
    } else {
        echo elgg_view_resource('members/index', [
            'page' => $page[0],
        ]);
    }
    return true;
}
function my_members_nav_newest($hook, $type, $returnvalue, $params) {
        $returnvalue['newest'] = array(
            'title' => elgg_echo('sort:newest'),
            'url' => "members/newest",
        );
     return $returnvalue;
}