This commit is contained in:
Ilya Tregubov 2022-04-04 10:47:10 +06:00
commit b470097bdb
5 changed files with 74 additions and 13 deletions

View File

@ -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 = '';

View File

@ -28,18 +28,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 = '';

View File

@ -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 = '';

View File

@ -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 <http://www.gnu.org/licenses/>.
}}
{{!
@template core_admin/header_search_input
Admin search input for page header.
Example context (json):
{
"action": "http://moodle.local/admin/search.php",
"query": "themedesigner"
}
}}
<div class="simplesearchform d-flex justify-content-end">
<form autocomplete="off" action="{{action}}" method="get" accept-charset="utf-8" class="mform form-inline simplesearchform">
<div class="input-group">
<label for="searchinput-{{uniqid}}">
<span class="sr-only">{{#str}} search, core {{/str}}</span>
</label>
<input type="text"
id="searchinput-{{uniqid}}"
class="form-control"
placeholder="{{#str}} search, core {{/str}}"
aria-label="{{#str}} search, core {{/str}}"
name="query"
data-region="input"
autocomplete="off"
{{#query}}value="{{.}}"{{/query}}
>
<div class="input-group-append">
<button type="submit" class="btn btn-primary search-icon">
{{#pix}} a/search, core {{/pix}}
<span class="sr-only">{{#str}} search, core {{/str}}</span>
</button>
</div>
</div>
</form>
</div>

View File

@ -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();
}