Hello Jean-Roch,
Working with my collegue,
Dominique Palumbo, we finally found a way to have a customized action menu while tweaking minimally the Moodle functions.
Here are the modifications we made on out Moodle 3.7.1.
These modifications should not be done one production Moodle without testing.
There is one file to adapt : /lib/outputrenderers.php
Here are the 2 functions tweaks ...
In public function context_header_settings_menu(), modify the build_action_menu_from_navigation call when if ($showcoursemenu), and set the last parameter ($onlytopleafnodes) to false.
This will generate an action menu with all options of the administration menu.
In protected function build_action_menu_from_navigation, add a specific class for each item of this menu (to then enable us to hide some of them through
css) :
Here are the 2 lines to add :
$myclass = parse_url($menuitem->action, PHP_URL_PATH);
$link->add_class(ltrim(str_replace('.php','',str_replace('/', '-', $myclass)),'-'));
This generates a class from the Moodle url.
For example, the link "http://my-moodle/course/completion.php?id=86" will be associated with class "course-completion".
Then it is possible to tweak the elements to show in the cog menu trough css.
Here is the customized css to apply to Boost Theme :
/* hide elements from cog action menu */
/* suppose to have modifications in moodle/lib/outputrenderers.php */
/* we suppress the vertical padding to the .dropdown block and apply an equivalent margin to the a tag used to integrate menu links */
/* this is necessary to have no space when hiding one menu element beacuse the custon class is weared by the a tag. */
.path-course #page-header .dropdown-item,
.path-mod #page-header .dropdown-item
{
padding: 0 1.5rem 0 1.5rem; /* default is padding:0.25rem 1.5rem; */
}
.path-course #page-header .dropdown-item a,
.path-mod #page-header .dropdown-item a
{
margin:0.25rem 0 0.25rem 0 ; /* default is none */
}
/* we also hide top leafes that are not link */
.path-course #page-header .dropdown-item span,
.path-mod #page-header .dropdown-item span
{
display:none;
}
/* we hide menu elements we want */
.path-course #page-header .dropdown-item .course-view,
.path-course #page-header .dropdown-item .course-completion,
.path-course #page-header .dropdown-item .enrol-editinstance,
.path-course #page-header .dropdown-item .admin-roles-permissions,
.path-course #page-header .dropdown-item .admin-roles-check,
.path-course #page-header .dropdown-item .enrol-manual-unenrolself,
.path-course #page-header .dropdown-item .enrol-self-unenrolself,
.path-course #page-header .dropdown-item .enrol-otherusers,
.path-course #page-header .dropdown-item .filter-manage,
.path-course #page-header .dropdown-item .report-competency-index,
.path-course #page-header .dropdown-item .report-editdates-index,
.path-course #page-header .dropdown-item .report-log-index,
.path-course #page-header .dropdown-item .report-loglive-index,
.path-course #page-header .dropdown-item .report-outline-index,
.path-course #page-header .dropdown-item .report-participation-index,
.path-course #page-header .dropdown-item .report-writeup-index,
.path-course #page-header .dropdown-item .badges-newbadge,
.path-course #page-header .dropdown-item .backup-backup,
.path-course #page-header .dropdown-item .backup-restorefile,
.path-course #page-header .dropdown-item .question-category,
.path-course #page-header .dropdown-item .question-import,
.path-course #page-header .dropdown-item .question-export,
.path-course #page-header .dropdown-item .local-purgequestioncategory-category
{
display:none !important;
}
/* the question bank link is dubbled and this is the trick to hide the second one */
.path-course #page-header .dropdown-menu .ml-4
{
margin-left:0 !important;
}
.path-course #page-header .dropdown-menu a.ml-4.question-edit
{
display:none !important;
}
/* we also hide some elements of the cog menu when on a specific ressource or activity */
.path-mod #page-header .dropdown-item .admin-roles-assign,
.path-mod #page-header .dropdown-item .admin-roles-permissions,
.path-mod #page-header .dropdown-item .admin-roles-check,
.path-mod #page-header .dropdown-item .filter-manage,
.path-mod #page-header .dropdown-item .report-competency-index,
.path-mod #page-header .dropdown-item .report-log-index,
.path-mod #page-header .dropdown-item .backup-backup,
.path-mod #page-header .dropdown-item .backup-restorefile,
.path-mod #page-header .dropdown-item .local-purgequestioncategory-category
{
display:none !important;
}
/* to make it elegant, we add icons to all shown elements of the cog menu */
/* for coherent presentation this icon is also used in the adminstration menu if more explicit */
.dropdown-item a.enrol-instances i::before,
{
content: "\f090"; /* sign-in replaced by f2f6 (sign-in-alt) in version 5 of Font Awesome */
font-family: FontAwesome;
}
.path-course #page-header .dropdown-item a.badges-index i::before
{
content: "\f0a3";
font-family: FontAwesome;
}
/* .path-course #page-header plus joli partout */
.dropdown-item a.question-edit i::before
{
content: "\f187";
font-family: FontAwesome;
}
.path-course #page-header .dropdown-item a.report-roster-index i::before
{
content: "\f030";
font-family: FontAwesome;
}
.path-course #page-header .dropdown-item a.report-progress-index i::before
{
content: "\f14a";
font-family: FontAwesome;
}
.path-course #page-header .dropdown-item a.grade-edit-tree-index i::before
{
content: "\f0ce";
font-family: FontAwesome;
}
And here come the miracle !
Note we also also tested the tweak on adaptable theme.
Same modifications have to be done in the moodle/theme/adaptable/renderers.php file.
And
the css is almost the same, except that the class ".path-course" has to
be replaced by ".pagelayout-course" and "#page-header" has to be
replaced by "#main-navbar".
Now I search a way to apply these changes without tweaking the core functions while developping a local plugin.
I submitted the adding of the class in the Moodle core :
https://tracker.moodle.org/browse/MDL-66494
I think it is a good way to open the possibility of building a plugin for cog menu customization trough interface.
There should be a checkbox to enable cog menu customization and a field to list the classes associated to blocks to hide.
It would be great for a first version ...
Thanks in advance for feedback ;-*
Zabelle