Commit 270dd871 authored by Frederic Massart's avatar Frederic Massart Committed by Dan Poltawski
Browse files

MDL-55474 block_search_forums: Convert search form to templates

Part of MDL-55071
parent 9727e142
......@@ -42,21 +42,9 @@ class block_search_forums extends block_base {
return $this->content;
}
$advancedsearch = get_string('advancedsearch', 'block_search_forums');
$strsearch = get_string('search');
$strgo = get_string('go');
$this->content->text = '<div class="searchform">';
$this->content->text .= '<form action="'.$CFG->wwwroot.'/mod/forum/search.php" style="display:inline"><fieldset class="invisiblefieldset">';
$this->content->text .= '<legend class="accesshide">'.$strsearch.'</legend>';
$this->content->text .= '<input name="id" type="hidden" value="'.$this->page->course->id.'" />'; // course
$this->content->text .= '<label class="accesshide" for="searchform_search">'.$strsearch.'</label>'.
'<input id="searchform_search" name="search" type="text" size="16" />';
$this->content->text .= '<button id="searchform_button" type="submit" title="'.$strsearch.'">'.$strgo.'</button><br />';
$this->content->text .= '<a href="'.$CFG->wwwroot.'/mod/forum/search.php?id='.$this->page->course->id.'">'.$advancedsearch.'</a>';
$this->content->text .= $OUTPUT->help_icon('search');
$this->content->text .= '</fieldset></form></div>';
$output = $this->page->get_renderer('block_search_forums');
$searchform = new \block_search_forums\output\search_form($this->page->course->id);
$this->content->text = $output->render($searchform);
return $this->content;
}
......
<?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));
}
}
<?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;
}
}
<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>
......@@ -2,3 +2,8 @@
position: relative;
left: initial;
}
.block_search_forums .searchform {
/* Override plugin's default. */
text-align: left;
}
<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>
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment