【问题标题】:.Moodle Local plugin , menu item not getting added to Site Administration.Moodle 本地插件,菜单项未添加到站点管理
【发布时间】:2015-05-22 11:08:42
【问题描述】:

我是 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);
    }
}

请帮忙。

【问题讨论】:

    标签: moodle


    【解决方案1】:

    我可以添加菜单项。我签入了 moodle/lib/navigationlib.php ,方法 load_administration_settings 中的类 settings_navigation ,以下行:

    $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 类被命名为 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);
        }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-07-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多