Add A Dropdown Menu To Moodle

Add A Dropdown Menu To Moodle

by Joseph Alvini -
Number of replies: 1

Ok so first and foremost I am new to Moodle Development and I am working at a great new job building on to an existing Moodle application. Currently I have to develop what should be a simple plugin to add a dropdown inside of all of the pages after a student or instructor logs in. 

I have seen multiple tutorials on plugins thorugh your docs but have not seen any plugins that span multiple pages.  So here are the details on what I am trying to make.

I want to build a toolbox that sits in the header and spans multiple pages.

I really would like to keep from touching the theme file too much as there are multiple themes and this can be a problem.

I definitely cannot touch any core moodle files as I was told not to LOL.


and here are some other specification:

currently I have some semblance of a plugin built.

I have the plugin outputting mustache files that will eventually query the Database for user selected items.


All in all I am very very new to moodle. If there is a tutorial out there for this that would be great. All of the tutorials I have encountered thus far have been to build a plugin but then that becomes its own page so to speak. As I said above I need this to span multiple pages (like a widget). 

If there are no tutorials out there I would settle on how I can get the templates  to just display without touching any core files. I was able to get it to display earlier by taking the following code and placing it in the outputrenderers.php but that idea is a no go per my boss LOL:

public function toolbar_menu(){
global $PAGE;
global $OUTPUT;
$renderable = new \local_toolboxtest\output\menu_wrapper();
$output = $PAGE->get_renderer('local_toolboxtest', 'menu_wrapper');
return $output->render($renderable);
}
 Is there anywhere else I can call this function from? Thanks in advance for any help. BTW I am using moodle 3.2.. 
Average of ratings: -
In reply to Joseph Alvini

Re: Add A Dropdown Menu To Moodle

by Justin Hunt -
Picture of Particularly helpful Moodlers Picture of Plugin developers

Well this does sound like something a theme plugin should do. 

 I think the best way would be to learn a little about overriding renderers in Moodle. Then you could find the renderer that is handling the location you want to customize. You would override that renderer and add your code to the output.

See here:

https://docs.moodle.org/dev/Overriding_a_renderer

The thing is that something has to call your renderer. If your renderer is part of the theme then its pretty straightforward. 

Otherwise you might make it part of a local plugin (not sure about that ..). 

I have overridden renderers without making a plugin or hacking anything come to think of it. I just wrote my renderer class and stuck it in the correct folder in the theme(e.g theme/boost/classes/output), so it would get picked up by class autoloading and applied.

If you post about this in the themes forum you might get a more knowledgable answer.