Hello,
I'm actually using moodle v3.5.3 with theme adptable v1.7.2.2 : 2018091905
I will speak only about the "navbar menu" : if it's not clear, it's corresponding mainly to this configuration page : http://127.0.0.1/admin/settings.php?section=theme_adaptable_navbar .The file corresponding is /theme/adaptable/layout/includes/header.php after ligne 373
In the beginning, I wanted to add some "items" in the menu, finally after looking the code I'm using the "tool menu" to add items in a tool menu, available in this page : http://127.0.0.1/admin/settings.php?section=theme_adaptable_header_navbar_menu (Now i need to think about what I exactly want to add and in how many tools menu to group item with some logic ^^)
So I made some changes in the file /theme/adaptable/renderers.php in the function tools_menu, so now, for each line in the toolmenu, i can add to the end of the line a list of capabilities I want to check to display or not this line (using same logic as original, separation is made using|).
Question 1 : Instead of modifying an existing file, is there a way to do my changes in a local plugin ?
Question 2 : By trying to answer question 1, I read this page https://docs.moodle.org/dev/Renderer_best_practices which clearly say :" DO NOT: Use logic that isn't essential to producing output. This includes but is not limited to the following: Access or capability checks. " . It's a bit problematic, it actually seems to be exactly what i'm doing ... So... what should I do instead (and how ) ?
I don't know if I should add this here, but if some one is interested in this modification or can give me some comments on it, the code i added in /theme/adaptable/renderers.php function tools_menu, after $menu is set on line 1911 is the following (being french, comments are in french too ..) :
//On explose le menu en tableau de ligne
$lignes_menu=explode("\n", $menu);
//pour chaque ligne du menu
foreach ($lignes_menu as $key=> $ligne) {
//on explose la ligne en tableau de cases
$cases= explode("|", $ligne);
//Si il y a plus de 3 cases, c'est que j'ai rajouté à la fin de la ligne une liste de droit qu'il faut posseder pour pouvoir voir l'element.
if(count($cases)>3)
{
//on va parcourir les cases qui sont supposés contenir des capability
for($i=3;$i<count($cases);$i++)
{
//on verifie que l'on a bien une capability, sinon on passe a la case suivante ..
if (!$capinfo = get_capability_info(trim($cases[$i]))) {
echo $cases[$i]." n'est pas une capacitée valide"; //Je ne sais pas si on laisse l'affichage ou pas, ca permet de voir rapidement qu'on a mal rempli le menu
continue; //on passe a la case suivante pour si il y a plusieurs capability
}
//si l'utilisateur n'a pas le droit de la capability de la case, on enleve la ligne du tableau de ligne
if (!has_capability(trim($cases[$i]), context_course::instance($PAGE->course->id))) {
// echo "L'utilisateur n'a pas la capacité ".$cases[$i];
unset($lignes_menu[$key]);
}
else
{
// echo "L'utilisateur a bien la capacité ".$cases[$i];
}
}
}
}
//une fois qu'on a fait toutes les lignes on reconstruit pour mettre à jour le menu en ayant enlevé les lignes qu'on voulait pas
$menu=implode("\n", $lignes_menu);