From b7417f2adfd977c4edd67e66dcf46f269901de4a Mon Sep 17 00:00:00 2001 From: Paul Holden Date: Thu, 31 Mar 2022 20:11:34 +0100 Subject: [PATCH] MDL-74026 admin: consistently show search element on admin pages. --- admin/category.php | 6 +++ admin/search.php | 12 ----- admin/settings.php | 7 +++ admin/templates/header_search_input.mustache | 52 ++++++++++++++++++++ lib/adminlib.php | 10 +++- 5 files changed, 74 insertions(+), 13 deletions(-) create mode 100644 admin/templates/header_search_input.mustache diff --git a/admin/category.php b/admin/category.php index 31df0629136..e11507a218a 100644 --- a/admin/category.php +++ b/admin/category.php @@ -48,6 +48,12 @@ if (!($settingspage->check_access())) { print_error('accessdenied', 'admin'); } +$hassiteconfig = has_capability('moodle/site:config', $PAGE->context); +if ($hassiteconfig) { + $PAGE->add_header_action($OUTPUT->render_from_template('core_admin/header_search_input', [ + 'action' => new moodle_url('/admin/search.php'), + ])); +} $statusmsg = ''; $errormsg = ''; diff --git a/admin/search.php b/admin/search.php index 8ddbd2b592b..eb81c70e94b 100644 --- a/admin/search.php +++ b/admin/search.php @@ -25,18 +25,6 @@ if ($hassiteconfig && moodle_needs_upgrading()) { admin_externalpage_setup('search', '', array('query' => $query)); // now hidden page $PAGE->set_heading(get_string('administrationsite')); // Has to be after setup since it has its' own heading set_heading. -if ($hassiteconfig) { - $data = [ - 'action' => new moodle_url('/admin/search.php'), - 'btnclass' => 'btn-primary', - 'inputname' => 'query', - 'searchstring' => get_string('search'), - 'query' => $query, - 'extraclasses' => 'd-flex justify-content-end' - ]; - $PAGE->add_header_action($OUTPUT->render_from_template('core/search_input', $data)); -} - $adminroot = admin_get_root(); // need all settings here $adminroot->search = $query; // So we can reference it in search boxes later in this invocation $statusmsg = ''; diff --git a/admin/settings.php b/admin/settings.php index 1df90252c54..7adbac3ac2f 100644 --- a/admin/settings.php +++ b/admin/settings.php @@ -33,6 +33,13 @@ if (!($settingspage->check_access())) { die; } +$hassiteconfig = has_capability('moodle/site:config', $PAGE->context); +if ($hassiteconfig) { + $PAGE->add_header_action($OUTPUT->render_from_template('core_admin/header_search_input', [ + 'action' => new moodle_url('/admin/search.php'), + ])); +} + /// WRITING SUBMITTED DATA (IF ANY) ------------------------------------------------------------------------------- $statusmsg = ''; diff --git a/admin/templates/header_search_input.mustache b/admin/templates/header_search_input.mustache new file mode 100644 index 00000000000..51a6386f105 --- /dev/null +++ b/admin/templates/header_search_input.mustache @@ -0,0 +1,52 @@ +{{! + This file is part of Moodle - http://moodle.org/ + + Moodle is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + Moodle is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with Moodle. If not, see . +}} +{{! + @template core_admin/header_search_input + + Admin search input for page header. + + Example context (json): + { + "action": "http://moodle.local/admin/search.php", + "query": "themedesigner" + } +}} +
+
+
+ + +
+ +
+
+
+
diff --git a/lib/adminlib.php b/lib/adminlib.php index fdc812747e7..65c04420d3d 100644 --- a/lib/adminlib.php +++ b/lib/adminlib.php @@ -8804,10 +8804,11 @@ function admin_externalpage_setup($section, $extrabutton = '', array $extraurlpa $adminroot = admin_get_root(false, false); // settings not required for external pages $extpage = $adminroot->locate($section, true); + $hassiteconfig = has_capability('moodle/site:config', context_system::instance()); if (empty($extpage) or !($extpage instanceof admin_externalpage)) { // The requested section isn't in the admin tree // It could be because the user has inadequate capapbilities or because the section doesn't exist - if (!has_capability('moodle/site:config', context_system::instance())) { + if (!$hassiteconfig) { // The requested section could depend on a different capability // but most likely the user has inadequate capabilities print_error('accessdenied', 'admin'); @@ -8878,6 +8879,13 @@ function admin_externalpage_setup($section, $extrabutton = '', array $extraurlpa $PAGE->set_title("$SITE->shortname: " . implode(": ", $visiblepathtosection)); $PAGE->set_heading($SITE->fullname); + if ($hassiteconfig) { + $PAGE->add_header_action($OUTPUT->render_from_template('core_admin/header_search_input', [ + 'action' => new moodle_url('/admin/search.php'), + 'query' => $PAGE->url->get_param('query'), + ])); + } + // prevent caching in nav block $PAGE->navigation->clear_cache(); }