--- /dev/null
+{{!
+ 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/checkbox
+
+ Chooser search template.
+
+ Example context (json):
+ {
+ "name": "fullsearch",
+ "id": "fullsearch",
+ "checked": true,
+ "value": "1",
+ "label": "Reset options"
+ }
+}}
+<div class="custom-control custom-checkbox">
+ <input type="checkbox" name={{{ name }}} class="custom-control-input" value={{{ value }}} id="{{{ id }}}" {{#checked}} checked="checked" {{/checked}}>
+ <label class="custom-control-label" for="{{{ id }}}">{{{ label }}}</label>
+</div>
\ No newline at end of file
</button>
</div>
</div>
+ {{#otherfields}}
+ <div class="ml-2">{{{ otherfields }}}</div>
+ {{/otherfields}}
</form>
</div>
\ No newline at end of file
}
public function export_for_template(renderer_base $output) {
+ $hiddenfields = [
+ (object) ['name' => 'id', 'value' => $this->courseid],
+ ];
$data = [
- 'actionurl' => $this->actionurl->out(false),
- 'courseid' => $this->courseid,
+ 'action' => $this->actionurl->out(false),
+ 'hiddenfields' => $hiddenfields,
'query' => $this->query,
'helpicon' => $this->helpicon->export_for_template($output),
+ 'inputname' => 'search',
+ 'searchstring' => get_string('searchforums', 'mod_forum')
];
return $data;
}
Example context (json):
{
- "actionurl": "https://domain.example/mod/forum/search.php",
- "courseid": "2",
+ "action": "https://domain.example/mod/forum/search.php",
"helpicon": "<a class='btn'><i class='icon fa fa-question-circle'></i></a>",
- "query": "find this post"
+ "query": "find this post",
+ "inputname": "search"
}
}}
-<div class="forumsearch">
- <form action="{{actionurl}}" class="form-inline">
- <input type="hidden" name="id" value="{{courseid}}">
- <div class="input-group">
- <div class="input-group-prepend">
- {{#helpicon}}
- {{>core/help_icon}}
- {{/helpicon}}
- </div>
- <label class="sr-only" for="search">{{#str}}search, forum{{/str}}</label>
- <input id="search" name="search" type="text" class="form-control" value="{{query}}">
- <div class="input-group-append">
- <button class="btn btn-secondary" id="searchforums" type="submit">{{#str}}searchforums, mod_forum{{/str}}</button>
- </div>
- </div>
-
- </form>
-</div>
+{{#helpicon}}
+ {{>core/help_icon}}
+{{/helpicon}}
+{{< core/search_input }}
+{{/ core/search_input }}
/// Search box
if ($showcommonelements ) {
- echo '<form method="post" class="form form-inline mb-1" action="' . $CFG->wwwroot . '/mod/glossary/view.php">';
-
-
- if ($mode == 'search') {
- echo '<input type="text" name="hook" size="20" value="'.s($hook).'" alt="'.$strsearch.'" class="form-control"/> ';
- } else {
- echo '<input type="text" name="hook" size="20" value="" alt="'.$strsearch.'" class="form-control"/> ';
- }
- echo '<input type="submit" value="'.$strsearch.'" name="searchbutton" class="btn btn-secondary mr-1"/> ';
+ $fullsearchchecked = false;
if ($fullsearch || $mode != 'search') {
- $fullsearchchecked = 'checked="checked"';
- } else {
- $fullsearchchecked = '';
- }
- echo '<span class="checkbox"><label for="fullsearch">';
- echo ' <input type="checkbox" name="fullsearch" id="fullsearch" value="1" '.$fullsearchchecked.'/> ';
- echo '<input type="hidden" name="mode" value="search" />';
- echo '<input type="hidden" name="id" value="'.$cm->id.'" />';
- echo $strsearchindefinition.'</label></span>';
-
- echo '</form>';
+ $fullsearchchecked = true;
+ }
+
+ $check = [
+ 'name' => 'fullsearch',
+ 'id' => 'fullsearch',
+ 'value' => '1',
+ 'checked' => $fullsearchchecked,
+ 'label' => $strsearchindefinition
+ ];
+
+ $checkbox = $OUTPUT->render_from_template('core/checkbox', $check);
+
+ $hiddenfields = [
+ (object) ['name' => 'id', 'value' => $cm->id],
+ (object) ['name' => 'mode', 'value' => 'search'],
+ ];
+ $data = [
+ 'action' => new moodle_url('/mod/glossary/view.php'),
+ 'hiddenfields' => $hiddenfields,
+ 'otherfields' => $checkbox,
+ 'inputname' => 'hook',
+ 'query' => ($mode == 'search') ? s($hook) : '',
+ 'searchstring' => get_string('search'),
+ 'extraclasses' => 'my-2'
+ ];
+ echo $OUTPUT->render_from_template('core/search_input', $data);
}
/// Show the add entry button if allowed
}
}
+/**
+ * Search for wiki
+ *
+ * @param stdClass $cm course module object
+ * @param string $search searchword.
+ * @param stdClass $subwiki Optional Subwiki.
+ * @return Search wiki input form
+ */
function wiki_search_form($cm, $search = '', $subwiki = null) {
- global $CFG, $OUTPUT;
-
- $output = '<div class="wikisearch">';
- $output .= '<form method="post" action="' . $CFG->wwwroot . '/mod/wiki/search.php" style="display:inline">';
- $output .= '<fieldset class="invisiblefieldset">';
- $output .= '<legend class="accesshide">'. get_string('searchwikis', 'wiki') .'</legend>';
- $output .= '<label class="accesshide" for="searchwiki">' . get_string("searchterms", "wiki") . '</label>';
- $output .= '<input id="searchwiki" name="searchstring" type="text" size="18" value="' . s($search, true) . '" alt="search" />';
- $output .= '<input name="courseid" type="hidden" value="' . $cm->course . '" />';
- $output .= '<input name="cmid" type="hidden" value="' . $cm->id . '" />';
- if (!empty($subwiki->id)) {
- $output .= '<input name="subwikiid" type="hidden" value="' . $subwiki->id . '" />';
- }
- $output .= '<input name="searchwikicontent" type="hidden" value="1" />';
- $output .= '<input value="' . get_string('searchwikis', 'wiki') . '" class="btn btn-secondary" type="submit" />';
- $output .= '</fieldset>';
- $output .= '</form>';
- $output .= '</div>';
+ global $OUTPUT;
- return $output;
+ $hiddenfields = [
+ (object) ['type' => 'hidden', 'name' => 'courseid', 'value' => $cm->course],
+ (object) ['type' => 'hidden', 'name' => 'cmid', 'value' => $cm->id],
+ (object) ['type' => 'hidden', 'name' => 'searchwikicontent', 'value' => 1],
+ ];
+ if (!empty($subwiki->id)) {
+ $hiddenfields[] = (object) ['type' => 'hidden', 'name' => 'subwikiid', 'value' => $subwiki->id];
+ }
+ $data = [
+ 'action' => new moodle_url('/mod/wiki/search.php'),
+ 'hiddenfields' => $hiddenfields,
+ 'inputname' => 'searchstring',
+ 'query' => s($search, true),
+ 'searchstring' => get_string('searchwikis', 'wiki'),
+ 'extraclasses' => 'mt-2'
+ ];
+ return $OUTPUT->render_from_template('core/search_input', $data);
}
+
function wiki_extend_navigation(navigation_node $navref, $course, $module, $cm) {
global $CFG, $PAGE, $USER;