.Moodle 本地插件,菜单项未添加到站点管理

.Moodle Local plugin , menu item not getting added to Site Administration

我是moodle的新手。我创建了一个本地插件 setmotd。

新菜单项未添加到站点管理。

使用 moodle 2.8.5

在 lib.php 中我放置了函数 :

function local_setmotd_extends_settings_navigation($settingsnav, $context)
{
    global $CFG, $PAGE;

    /*
    // Only let users with the appropriate capability see this settings item.
    if( ! has_capability('local_plugin/setmotd:view', $context) )
    {
        return;
    }
    */

    if($settingnode = $settingsnav->find('root', navigation_node::TYPE_SETTING))
    {
        $setMotdMenuLbl = get_string('menutitle', 'local_setmotd');
        $setMotdUrl = new moodle_url('/local/setmotd/set_motd.php');
        $setMotdnode = navigation_node::create(
            $setMotdMenuLbl,
            $setMotdUrl,
            navigation_node::NODETYPE_LEAF);
        if ($PAGE->setMotdUrl->compare($setMotdUrl, URL_MATCH_BASE)) {
            $setMotdnode->make_active();
        }
        $settingnode->add_node($setMotdnode);
    }
}

请帮忙。

我可以添加菜单 item.I 在 moodle/lib/navigationlib.php 中签入,class settings_navigation 在方法 load_administration_settings 中,如下行:

$referencebranch = $this->add(get_string('administrationsite'), null, self::TYPE_SITE_ADMIN, null, 'root');

所以,对于 "root",navigation_node 类型 必须是 TYPE_SITE_ADMIN,而不是 TYPE_SETTING.

在 firefox firebug 中,我早些时候在 ajax 加载站点管理菜单的调用中注意到 "root" 的 css class 是名为 TYPE_SITE_ADMIN.

请注意,我还无法激活新菜单项。请注意,使用 $PAGE 的部分已被注释。

    function local_setmotd_extends_settings_navigation(settings_navigation $settingsnav, context $context)
{
    global $CFG, $PAGE;

    /*
    // Only let users with the appropriate capability see this settings item.
    if( ! has_capability('local/setmotd:view', $context) )
    {
        return;
    }
    */
    $settingnode = $settingsnav->find('root', navigation_node::TYPE_SITE_ADMIN);
    if( $settingnode )
    {
        $setMotdMenuLbl = get_string('menutitle', 'local_setmotd');
        $setMotdUrl = new moodle_url('/local/setmotd/set_motd.php');
        $setMotdnode = navigation_node::create(
            $setMotdMenuLbl,
            $setMotdUrl,
            navigation_node::NODETYPE_LEAF);
        /*
        if ($PAGE->$setMotdUrl->compare($setMotdUrl, URL_MATCH_BASE)) {
            $setMotdnode->make_active();
        }
        */
        $settingnode->add_node($setMotdnode);
    }
}