How to add "settings cog" to your module

How to add "settings cog" to your module

by Oleg Sychev -
Number of replies: 2
Picture of Core developers Picture of Plugin developers

Navigation links inside a module seemed to move under "Settings cog" in Moodle modules.

However, maintaining our plugins, I can't find a way to get this big cog wheel appearing on "view" page of my module.

Unfortunately, the documentation on https://docs.moodle.org/dev/Boost_Navigation says just "These functions will (only on certain pages) add all the nodes from the settings nav tree into a flat menu. ... The "only on certain pages" mentioned above means ... TODO"

So, how can I make my page one of these blessed "certain pages"?

Average of ratings: -
In reply to Oleg Sychev

Re: How to add "settings cog" to your module

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

Try adding this in the same place you set up your page url , title, and heading, before you send out the header

$PAGE->force_settings_menu(true);
I have also wondered how this works. It seems to magically add it there on your mod's view.php page, but I am not quite sure why. 
In reply to Oleg Sychev

Re: How to add "settings cog" to your module

by Neill Magill -
Picture of Core developers Picture of Peer reviewers Picture of Plugin developers
A settings menu in an activity looks as though it will show up automatically only if:

  1. The context level is for a module
  2. The active navigation node is for an activity or resource
  3. The navbar does not show any additional nodes

The code for it is in core_renderer::region_main_settings_menu()

It does mean that you can only force a settings menu in the activity context (anywhere else it will be ignored)