Local plugin , menu item not getting added to Site Administration

Local plugin , menu item not getting added to Site Administration

by Bhargava S -
Number of replies: 1

I am new to moodle. I have created a local plugin setmotd.

A new menu item is not getting added to Site Administration.

Using moodle 2.8.5 and genesis theme( purchased ).

In lib.php i have placed function :

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

Average of ratings: -
In reply to Bhargava S

Re: Local plugin , menu item not getting added to Site Administration

by Bhargava S -
I am now able to add menu item.

Updated code :
    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');

            $setMotdAdminNode = navigation_node::create(
                $setMotdMenuLbl,
                $setMotdUrl,
                navigation_node::NODETYPE_LEAF);

            file_put_contents('f:\chinanovation\my-logs\my-log.txt',"MA#".$PAGE->url."#".URL_MATCH_BASE);
            if ($PAGE->url->compare($setMotdUrl, URL_MATCH_BASE)) {
                $setMotdAdminNode->make_active();
            }
            $settingnode->add_node($setMotdAdminNode);
        }
    }


Average of ratings: Useful (1)