diff --git a/admin/settings/appearance.php b/admin/settings/appearance.php index 1dce8ecc559..b766095ba1e 100644 --- a/admin/settings/appearance.php +++ b/admin/settings/appearance.php @@ -330,6 +330,10 @@ if ($hassiteconfig or has_any_capability($capabilities, $systemcontext)) { // sp $temp->add(new admin_setting_configcheckbox('logininfoinsecurelayout', new lang_string('logininfoinsecurelayout', 'admin'), new lang_string('logininfoinsecurelayout_desc', 'admin'), 0)); + // Process primary navigation (custom menu) through Moodle filters. + $temp->add(new admin_setting_configcheckbox('navfilter', + new lang_string('navfilter', 'admin'), + new lang_string('navfilter_desc', 'admin'), 0)); $temp->add(new admin_setting_configtextarea('custommenuitems', new lang_string('custommenuitems', 'admin'), new lang_string('configcustommenuitems', 'admin'), '', PARAM_RAW, '50', '10')); $defaultsettingcustomusermenuitems = [ diff --git a/admin/tool/mobile/classes/api.php b/admin/tool/mobile/classes/api.php index a8ef1ca6374..824ea13b0e0 100644 --- a/admin/tool/mobile/classes/api.php +++ b/admin/tool/mobile/classes/api.php @@ -320,7 +320,14 @@ class api { $settings->tool_mobile_customlangstrings = get_config('tool_mobile', 'customlangstrings'); $settings->tool_mobile_disabledfeatures = get_config('tool_mobile', 'disabledfeatures'); $settings->tool_mobile_filetypeexclusionlist = get_config('tool_mobile', 'filetypeexclusionlist'); - $settings->tool_mobile_custommenuitems = get_config('tool_mobile', 'custommenuitems'); + $custommenuitems = get_config('tool_mobile', 'custommenuitems'); + // If filtering of the primary custom menu is enabled, apply only the string filters. + if (!empty($CFG->navfilter && !empty($CFG->stringfilters))) { + // Apply filters that are enabled for Content and Headings. + $filtermanager = \filter_manager::instance(); + $custommenuitems = $filtermanager->filter_string($custommenuitems, \context_system::instance()); + } + $settings->tool_mobile_custommenuitems = $custommenuitems; $settings->tool_mobile_apppolicy = get_config('tool_mobile', 'apppolicy'); // This setting could be not set in some edge cases such as bad upgrade. $mintimereq = get_config('tool_mobile', 'autologinmintimebetweenreq'); diff --git a/lang/en/admin.php b/lang/en/admin.php index 31eecddf3f0..5f83e216129 100644 --- a/lang/en/admin.php +++ b/lang/en/admin.php @@ -920,6 +920,8 @@ $string['minpasswordnonalphanum'] = 'Non-alphanumeric characters'; $string['minpasswordupper'] = 'Uppercase letters'; $string['misc'] = 'Miscellaneous'; $string['mlbackendsettings'] = 'Machine learning backend settings'; +$string['navfilter'] = 'Filter custom menu'; +$string['navfilter_desc'] = 'Process the custom menu through Moodle filters that are set to apply to Content and Headings. Useful for enabling dynamic custom menu items.'; $string['mnetrestore_extusers'] = 'Note: This backup file contains remote Moodle Network user accounts which will be restored as part of the process.'; $string['mnetrestore_extusers_admin'] = 'Note: This backup file seems to come from a different Moodle installation and contains remote Moodle Network user accounts. The restore process will try to match the Moodle Network hosts for all created users. Those not matching will be automatically switched to internal authentication (instead of mnet one). The restore log will inform you about that.'; $string['mnetrestore_extusers_mismatch'] = 'Note: This backup file apparently originates from a different Moodle installation and contains remote Moodle Network user accounts that may fail to restore. This operation is unsupported. If you are certain that it was created on this Moodle installation, or you can ensure that all the needed Moodle Network Hosts are configured, you may want to still try the restore.'; diff --git a/lib/classes/navigation/output/primary.php b/lib/classes/navigation/output/primary.php index 48534b8fa21..238e2297530 100644 --- a/lib/classes/navigation/output/primary.php +++ b/lib/classes/navigation/output/primary.php @@ -20,6 +20,7 @@ use renderable; use renderer_base; use templatable; use custom_menu; +use filter_manager; /** * Primary navigation renderable @@ -119,6 +120,14 @@ class primary implements renderable, templatable { } $custommenuitems = $CFG->custommenuitems; + + // If filtering of the primary custom menu is enabled, apply only the string filters. + if (!empty($CFG->navfilter && !empty($CFG->stringfilters))) { + // Apply filters that are enabled for Content and Headings. + $filtermanager = \filter_manager::instance(); + $custommenuitems = $filtermanager->filter_string($custommenuitems, \context_system::instance()); + } + $currentlang = current_language(); $custommenunodes = custom_menu::convert_text_to_menu_nodes($custommenuitems, $currentlang); $nodes = []; diff --git a/lib/classes/output/core_renderer.php b/lib/classes/output/core_renderer.php index 45442bbc61e..7a92c6f43fe 100644 --- a/lib/classes/output/core_renderer.php +++ b/lib/classes/output/core_renderer.php @@ -3486,6 +3486,14 @@ EOD; if (empty($custommenuitems) && !empty($CFG->custommenuitems)) { $custommenuitems = $CFG->custommenuitems; } + + // If filtering of the primary custom menu is enabled, apply only the string filters. + if (!empty($CFG->navfilter && !empty($CFG->stringfilters))) { + // Apply filters that are enabled for Content and Headings. + $filtermanager = \filter_manager::instance(); + $custommenuitems = $filtermanager->filter_string($custommenuitems, \context_system::instance()); + } + $custommenu = new custom_menu($custommenuitems, current_language()); return $this->render_custom_menu($custommenu); } @@ -3501,6 +3509,14 @@ EOD; if (empty($custommenuitems) && !empty($CFG->custommenuitems)) { $custommenuitems = $CFG->custommenuitems; } + + // If filtering of the primary custom menu is enabled, apply only the string filters. + if (!empty($CFG->navfilter && !empty($CFG->stringfilters))) { + // Apply filters that are enabled for Content and Headings. + $filtermanager = \filter_manager::instance(); + $custommenuitems = $filtermanager->filter_string($custommenuitems, \context_system::instance()); + } + $custommenu = new custom_menu($custommenuitems, current_language()); $langs = get_string_manager()->get_list_of_translations(); $haslangmenu = $this->lang_menu() != '';