Skip to content

Commit 270dd87

Browse files
Frederic Massartdanpoltawski
authored andcommitted
MDL-55474 block_search_forums: Convert search form to templates
Part of MDL-55071
1 parent 9727e14 commit 270dd87

File tree

6 files changed

+164
-15
lines changed

6 files changed

+164
-15
lines changed

blocks/search_forums/block_search_forums.php

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -42,21 +42,9 @@ function get_content() {
4242
return $this->content;
4343
}
4444

45-
$advancedsearch = get_string('advancedsearch', 'block_search_forums');
46-
47-
$strsearch = get_string('search');
48-
$strgo = get_string('go');
49-
50-
$this->content->text = '<div class="searchform">';
51-
$this->content->text .= '<form action="'.$CFG->wwwroot.'/mod/forum/search.php" style="display:inline"><fieldset class="invisiblefieldset">';
52-
$this->content->text .= '<legend class="accesshide">'.$strsearch.'</legend>';
53-
$this->content->text .= '<input name="id" type="hidden" value="'.$this->page->course->id.'" />'; // course
54-
$this->content->text .= '<label class="accesshide" for="searchform_search">'.$strsearch.'</label>'.
55-
'<input id="searchform_search" name="search" type="text" size="16" />';
56-
$this->content->text .= '<button id="searchform_button" type="submit" title="'.$strsearch.'">'.$strgo.'</button><br />';
57-
$this->content->text .= '<a href="'.$CFG->wwwroot.'/mod/forum/search.php?id='.$this->page->course->id.'">'.$advancedsearch.'</a>';
58-
$this->content->text .= $OUTPUT->help_icon('search');
59-
$this->content->text .= '</fieldset></form></div>';
45+
$output = $this->page->get_renderer('block_search_forums');
46+
$searchform = new \block_search_forums\output\search_form($this->page->course->id);
47+
$this->content->text = $output->render($searchform);
6048

6149
return $this->content;
6250
}
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
<?php
2+
// This file is part of Moodle - http://moodle.org/
3+
//
4+
// Moodle is free software: you can redistribute it and/or modify
5+
// it under the terms of the GNU General Public License as published by
6+
// the Free Software Foundation, either version 3 of the License, or
7+
// (at your option) any later version.
8+
//
9+
// Moodle is distributed in the hope that it will be useful,
10+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
// GNU General Public License for more details.
13+
//
14+
// You should have received a copy of the GNU General Public License
15+
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
16+
17+
/**
18+
* Block search forums renderer.
19+
*
20+
* @package block_search_forums
21+
* @copyright 2016 Frédéric Massart - FMCorz.net
22+
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
23+
*/
24+
25+
namespace block_search_forums\output;
26+
defined('MOODLE_INTERNAL') || die();
27+
28+
use plugin_renderer_base;
29+
use renderable;
30+
31+
/**
32+
* Block search forums renderer.
33+
*
34+
* @package block_search_forums
35+
* @copyright 2016 Frédéric Massart - FMCorz.net
36+
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
37+
*/
38+
class renderer extends plugin_renderer_base {
39+
40+
/**
41+
* Render search form.
42+
*
43+
* @param renderable $searchform The search form.
44+
* @return string
45+
*/
46+
public function render_search_form(renderable $searchform) {
47+
return $this->render_from_template('block_search_forums/search_form', $searchform->export_for_template($this));
48+
}
49+
50+
}
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
<?php
2+
// This file is part of Moodle - http://moodle.org/
3+
//
4+
// Moodle is free software: you can redistribute it and/or modify
5+
// it under the terms of the GNU General Public License as published by
6+
// the Free Software Foundation, either version 3 of the License, or
7+
// (at your option) any later version.
8+
//
9+
// Moodle is distributed in the hope that it will be useful,
10+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
// GNU General Public License for more details.
13+
//
14+
// You should have received a copy of the GNU General Public License
15+
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
16+
17+
/**
18+
* Search form renderable.
19+
*
20+
* @package block_search_forums
21+
* @copyright 2016 Frédéric Massart - FMCorz.net
22+
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
23+
*/
24+
25+
namespace block_search_forums\output;
26+
defined('MOODLE_INTERNAL') || die();
27+
28+
use help_icon;
29+
use moodle_url;
30+
use renderable;
31+
use renderer_base;
32+
use templatable;
33+
34+
/**
35+
* Search form renderable class.
36+
*
37+
* @package block_search_forums
38+
* @copyright 2016 Frédéric Massart - FMCorz.net
39+
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
40+
*/
41+
class search_form implements renderable, templatable {
42+
43+
/** @var int The course ID. */
44+
protected $courseid;
45+
/** @var moodle_url The form action URL. */
46+
protected $actionurl;
47+
/** @var moodle_url The advanced search URL. */
48+
protected $advancedsearchurl;
49+
/** @var help_icon The help icon. */
50+
protected $helpicon;
51+
52+
/**
53+
* Constructor.
54+
*
55+
* @param int $courseid The course ID.
56+
*/
57+
public function __construct($courseid) {
58+
$this->courseid = $courseid;
59+
$this->actionurl = new moodle_url('/mod/forum/search.php');
60+
$this->advancedsearchurl = new moodle_url('/mod/forum/search.php', ['id' => $this->courseid]);
61+
$this->helpicon = new help_icon('search', 'core');
62+
}
63+
64+
public function export_for_template(renderer_base $output) {
65+
$data = [
66+
'actionurl' => $this->actionurl->out(false),
67+
'courseid' => $this->courseid,
68+
'advancedsearchurl' => $this->advancedsearchurl->out(false),
69+
'helpicon' => $this->helpicon->export_for_template($output),
70+
];
71+
return $data;
72+
}
73+
74+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<div class="searchform">
2+
<form action="{{actionurl}}" style="display: inline;">
3+
<fieldset class="invisiblefieldset">
4+
<legend class="accesshide">{{#str}}search{{/str}}</legend>
5+
<input type="hidden" name="id" value="{{courseid}}">
6+
<label class="accesshide" for="searchform_search">{{#str}}search{{/str}}</label>
7+
<input id="searchform_search" name="search" type="text" size="16">
8+
<button id="searchform_button" type="submit" title={{#quote}}{{#str}}search{{/str}}{{/quote}}>{{#str}}go{{/str}}</button><br>
9+
<a href="{{advancedsearchurl}}">{{#str}}advancedsearch, block_search_forums{{/str}}</a>
10+
{{#helpicon}}
11+
{{>core/help_icon}}
12+
{{/helpicon}}
13+
</fieldset>
14+
</form>
15+
</div>

theme/noname/scss/moodle/blocks.scss

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,8 @@
22
position: relative;
33
left: initial;
44
}
5+
6+
.block_search_forums .searchform {
7+
/* Override plugin's default. */
8+
text-align: left;
9+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<div class="searchform">
2+
<form action="{{actionurl}}" class="form-inline">
3+
<input type="hidden" name="id" value="{{courseid}}">
4+
<div class="form-group">
5+
<label class="sr-only" for="searchform_search">{{#str}}search{{/str}}</label>
6+
<input id="searchform_search" name="search" type="text" class="form-control" size="10">
7+
</div>
8+
<button class="btn btn-secondary" id="searchform_button" type="submit">{{#str}}go{{/str}}</button>
9+
</fieldset>
10+
</form>
11+
<div class="m-t-1">
12+
<a href="{{advancedsearchurl}}">{{#str}}advancedsearch, block_search_forums{{/str}}</a>
13+
{{#helpicon}}
14+
{{>core/help_icon}}
15+
{{/helpicon}}
16+
</div>
17+
</div>

0 commit comments

Comments
 (0)