From 1a2a52d12166edb44a54dd9242a43eae98f19edc Mon Sep 17 00:00:00 2001 From: Bas Brands Date: Mon, 31 Aug 2020 08:11:30 +0000 Subject: [PATCH] MDL-69454 core_search: consistent navbar search --- lang/en/moodle.php | 1 + lib/outputrenderers.php | 32 ++---- lib/templates/popover_region.mustache | 2 +- lib/templates/search_input_navbar.mustache | 116 ++++++++++++++++++++ message/templates/message_popover.mustache | 2 +- search/tests/behat/behat_search.php | 6 +- theme/boost/scss/moodle/core.scss | 9 ++ theme/boost/scss/moodle/popover-region.scss | 8 -- theme/boost/scss/moodle/search.scss | 102 +++++++++-------- theme/boost/style/moodle.css | 105 +++++++++++------- theme/boost/templates/navbar.mustache | 33 ++++-- theme/classic/style/moodle.css | 105 +++++++++++------- theme/classic/templates/navbar.mustache | 10 +- 13 files changed, 354 insertions(+), 177 deletions(-) create mode 100644 lib/templates/search_input_navbar.mustache diff --git a/lang/en/moodle.php b/lang/en/moodle.php index 2d8bd7267fe4a..602f1baeb2b39 100644 --- a/lang/en/moodle.php +++ b/lang/en/moodle.php @@ -2096,6 +2096,7 @@ $string['todaylogs'] = 'Today\'s logs'; $string['toeveryone'] = 'to everyone'; $string['toggleemojipicker'] = 'Toggle emoji picker'; +$string['togglesearch'] = 'Toggle search input'; $string['toomanybounces'] = 'That email address has had too many bounces. You must change it to continue.'; $string['toomanytags'] = 'This search included too many tags; some will have been ignored.'; $string['toomanytoshow'] = 'There are too many users to show.'; diff --git a/lib/outputrenderers.php b/lib/outputrenderers.php index ba5366fc048ba..dd9bd247977c4 100644 --- a/lib/outputrenderers.php +++ b/lib/outputrenderers.php @@ -3222,31 +3222,13 @@ public function search_box($id = false) { return ''; } - if ($id == false) { - $id = uniqid(); - } else { - // Needs to be cleaned, we use it for the input id. - $id = clean_param($id, PARAM_ALPHANUMEXT); - } - - // JS to animate the form. - $this->page->requires->js_call_amd('core/search-input', 'init', array($id)); - - $searchicon = html_writer::tag('div', $this->pix_icon('a/search', get_string('search', 'search'), 'moodle'), - array('role' => 'button', 'tabindex' => 0)); - $formattrs = array('class' => 'search-input-form', 'action' => $CFG->wwwroot . '/search/index.php'); - $inputattrs = array('type' => 'text', 'name' => 'q', 'placeholder' => get_string('search', 'search'), - 'size' => 13, 'tabindex' => -1, 'id' => 'id_q_' . $id, 'class' => 'form-control'); - - $contents = html_writer::tag('label', get_string('enteryoursearchquery', 'search'), - array('for' => 'id_q_' . $id, 'class' => 'accesshide')) . html_writer::empty_tag('input', $inputattrs); - if ($this->page->context && $this->page->context->contextlevel !== CONTEXT_SYSTEM) { - $contents .= html_writer::empty_tag('input', ['type' => 'hidden', - 'name' => 'context', 'value' => $this->page->context->id]); - } - $searchinput = html_writer::tag('form', $contents, $formattrs); - - return html_writer::tag('div', $searchicon . $searchinput, array('class' => 'search-input-wrapper nav-link', 'id' => $id)); + $data = [ + 'action' => new moodle_url('/search/index.php'), + 'hiddenfields' => (object) ['name' => 'context', 'value' => $this->page->context->id], + 'inputname' => 'q', + 'searchstring' => get_string('search'), + ]; + return $this->render_from_template('core/search_input_navbar', $data); } /** diff --git a/lib/templates/popover_region.mustache b/lib/templates/popover_region.mustache index 2047541cfabf0..610681e53249e 100644 --- a/lib/templates/popover_region.mustache +++ b/lib/templates/popover_region.mustache @@ -36,7 +36,7 @@