forked from moodle/moodle
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
MDL-55474 block_search_forums: Convert search form to templates
Part of MDL-55071
- Loading branch information
1 parent
9727e14
commit 270dd87
Showing
6 changed files
with
164 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
<?php | ||
// 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/>. | ||
|
||
/** | ||
* Block search forums renderer. | ||
* | ||
* @package block_search_forums | ||
* @copyright 2016 Frédéric Massart - FMCorz.net | ||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later | ||
*/ | ||
|
||
namespace block_search_forums\output; | ||
defined('MOODLE_INTERNAL') || die(); | ||
|
||
use plugin_renderer_base; | ||
use renderable; | ||
|
||
/** | ||
* Block search forums renderer. | ||
* | ||
* @package block_search_forums | ||
* @copyright 2016 Frédéric Massart - FMCorz.net | ||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later | ||
*/ | ||
class renderer extends plugin_renderer_base { | ||
|
||
/** | ||
* Render search form. | ||
* | ||
* @param renderable $searchform The search form. | ||
* @return string | ||
*/ | ||
public function render_search_form(renderable $searchform) { | ||
return $this->render_from_template('block_search_forums/search_form', $searchform->export_for_template($this)); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
<?php | ||
// 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/>. | ||
|
||
/** | ||
* Search form renderable. | ||
* | ||
* @package block_search_forums | ||
* @copyright 2016 Frédéric Massart - FMCorz.net | ||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later | ||
*/ | ||
|
||
namespace block_search_forums\output; | ||
defined('MOODLE_INTERNAL') || die(); | ||
|
||
use help_icon; | ||
use moodle_url; | ||
use renderable; | ||
use renderer_base; | ||
use templatable; | ||
|
||
/** | ||
* Search form renderable class. | ||
* | ||
* @package block_search_forums | ||
* @copyright 2016 Frédéric Massart - FMCorz.net | ||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later | ||
*/ | ||
class search_form implements renderable, templatable { | ||
|
||
/** @var int The course ID. */ | ||
protected $courseid; | ||
/** @var moodle_url The form action URL. */ | ||
protected $actionurl; | ||
/** @var moodle_url The advanced search URL. */ | ||
protected $advancedsearchurl; | ||
/** @var help_icon The help icon. */ | ||
protected $helpicon; | ||
|
||
/** | ||
* Constructor. | ||
* | ||
* @param int $courseid The course ID. | ||
*/ | ||
public function __construct($courseid) { | ||
$this->courseid = $courseid; | ||
$this->actionurl = new moodle_url('/mod/forum/search.php'); | ||
$this->advancedsearchurl = new moodle_url('/mod/forum/search.php', ['id' => $this->courseid]); | ||
$this->helpicon = new help_icon('search', 'core'); | ||
} | ||
|
||
public function export_for_template(renderer_base $output) { | ||
$data = [ | ||
'actionurl' => $this->actionurl->out(false), | ||
'courseid' => $this->courseid, | ||
'advancedsearchurl' => $this->advancedsearchurl->out(false), | ||
'helpicon' => $this->helpicon->export_for_template($output), | ||
]; | ||
return $data; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<div class="searchform"> | ||
<form action="{{actionurl}}" style="display: inline;"> | ||
<fieldset class="invisiblefieldset"> | ||
<legend class="accesshide">{{#str}}search{{/str}}</legend> | ||
<input type="hidden" name="id" value="{{courseid}}"> | ||
<label class="accesshide" for="searchform_search">{{#str}}search{{/str}}</label> | ||
<input id="searchform_search" name="search" type="text" size="16"> | ||
<button id="searchform_button" type="submit" title={{#quote}}{{#str}}search{{/str}}{{/quote}}>{{#str}}go{{/str}}</button><br> | ||
<a href="{{advancedsearchurl}}">{{#str}}advancedsearch, block_search_forums{{/str}}</a> | ||
{{#helpicon}} | ||
{{>core/help_icon}} | ||
{{/helpicon}} | ||
</fieldset> | ||
</form> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 17 additions & 0 deletions
17
theme/noname/templates/block_search_forums/search_form.mustache
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<div class="searchform"> | ||
<form action="{{actionurl}}" class="form-inline"> | ||
<input type="hidden" name="id" value="{{courseid}}"> | ||
<div class="form-group"> | ||
<label class="sr-only" for="searchform_search">{{#str}}search{{/str}}</label> | ||
<input id="searchform_search" name="search" type="text" class="form-control" size="10"> | ||
</div> | ||
<button class="btn btn-secondary" id="searchform_button" type="submit">{{#str}}go{{/str}}</button> | ||
</fieldset> | ||
</form> | ||
<div class="m-t-1"> | ||
<a href="{{advancedsearchurl}}">{{#str}}advancedsearch, block_search_forums{{/str}}</a> | ||
{{#helpicon}} | ||
{{>core/help_icon}} | ||
{{/helpicon}} | ||
</div> | ||
</div> |