Skip to content

Commit

Permalink
prevent help menu from displaying if it is turned off or empty.
Browse files Browse the repository at this point in the history
  • Loading branch information
stopfstedt committed Mar 13, 2024
1 parent daddfb9 commit b647fbc
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 43 deletions.
27 changes: 3 additions & 24 deletions classes/output/helpmenu.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,9 @@ class helpmenu implements renderable, templatable {
public function export_for_template(renderer_base $output): stdClass {
$menu = new stdClass();
$menu->items = [];
$menu->showmenu = false;

if (!$this->show_menu()) {
if (!config::get_setting('helpfeedbackenabled')) {
return $menu;
}

Expand All @@ -60,29 +61,7 @@ public function export_for_template(renderer_base $output): stdClass {
];
}
}

$menu->showmenu = !empty($menu->items);
return $menu;
}

/**
* Determine if the help menu should be shown.
*
* @return bool
* @throws dml_exception
*/
protected function show_menu(): bool {
if (!config::get_setting('helpfeedbackenabled')) {
return false;
}

// Check if at least one of the menu items actually contains a link.
for ($i = 1; $i <= constants::HELPMENU_ITEMS_COUNT; $i++) {
$url = config::get_setting('helpfeedback' . $i . 'link', '');
if (!empty($url)) {
return true;
}
}

return false;
}
}
39 changes: 21 additions & 18 deletions templates/helpmenu.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -32,24 +32,27 @@
"title": "Foo Bar",
"target": "_blank"
}
]
],
"showmenu": true
}
}}
<div class="ucsf-helpmenu dropdown">
<span class="dropdown-toggle nav-link"
tabindex="0"
id="ucsf-helpmenu-dropdown-toggle"
data-toggle="dropdown"
aria-haspopup="true"
aria-expanded="false"
aria-label="{{#str}}togglehelpmenu, theme_ucsf{{/str}}"
role="button"
>
{{#pix}}e/help{{/pix}}
</span>
<div class="dropdown-menu dropdown-menu-right" aria-labelledby="ucsf-helpmenu-dropdown-toggle" role="menu">
{{#items}}
<a class="dropdown-item" href="{{url}}" role="menuitem" tabindex="-1" target="{{target}}">{{title}}</a>
{{/items}}
{{#showmenu}}
<div class="ucsf-helpmenu dropdown">
<span class="dropdown-toggle nav-link"
tabindex="0"
id="ucsf-helpmenu-dropdown-toggle"
data-toggle="dropdown"
aria-haspopup="true"
aria-expanded="false"
aria-label="{{#str}}togglehelpmenu, theme_ucsf{{/str}}"
role="button"
>
{{#pix}}e/help{{/pix}}
</span>
<div class="dropdown-menu dropdown-menu-right" aria-labelledby="ucsf-helpmenu-dropdown-toggle" role="menu">
{{#items}}
<a class="dropdown-item" href="{{url}}" role="menuitem" tabindex="-1" target="{{target}}">{{title}}</a>
{{/items}}
</div>
</div>
</div>
{{/showmenu}}
2 changes: 1 addition & 1 deletion version.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
defined('MOODLE_INTERNAL') || die();

$plugin->component = 'theme_ucsf';
$plugin->version = 2024030900;
$plugin->version = 2024031300;
$plugin->release = 'v4.1';
$plugin->requires = 2022112800;
$plugin->supported = [401, 401];
Expand Down

0 comments on commit b647fbc

Please sign in to comment.