Skip to content

Commit

Permalink
MDL-55701 output: Adding core template for help_icon
Browse files Browse the repository at this point in the history
We didn't intend to do this, but as I made the mistake of extending
core/help_icon in a core template without realising that it
works solely because I had that template in the new theme, I
decided to add this template to core too.

Part of MDL-55071
  • Loading branch information
Frederic Massart authored and danpoltawski committed Sep 23, 2016
1 parent ecfad63 commit a84eadb
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 33 deletions.
11 changes: 11 additions & 0 deletions lib/outputcomponents.php
Original file line number Diff line number Diff line change
Expand Up @@ -499,6 +499,8 @@ public function diag_strings() {
* @return array
*/
public function export_for_template(renderer_base $output) {
global $CFG;

$title = get_string($this->identifier, $this->component);

if (empty($this->linktext)) {
Expand All @@ -508,7 +510,16 @@ public function export_for_template(renderer_base $output) {
}

$data = get_formatted_help_string($this->identifier, $this->component, false);

$data->alt = $alt;
$data->icon = (new pix_icon('help', $alt, 'core', ['class' => 'iconhelp']))->export_for_template($output);
$data->linktext = $this->linktext;
$data->title = get_string('helpprefix2', '', trim($title, ". \t"));
$data->url = (new moodle_url($CFG->httpswwwroot . '/help.php', [
'component' => $this->component,
'identifier' => $this->identifier,
'lang' => current_language()
]))->out(false);

$data->ltr = !right_to_left();
return $data;
Expand Down
34 changes: 1 addition & 33 deletions lib/outputrenderers.php
Original file line number Diff line number Diff line change
Expand Up @@ -2412,39 +2412,7 @@ public function help_icon($identifier, $component = 'moodle', $linktext = '') {
* @return string HTML fragment
*/
protected function render_help_icon(help_icon $helpicon) {
global $CFG;

// first get the help image icon
$src = $this->pix_url('help');

$title = get_string($helpicon->identifier, $helpicon->component);

if (empty($helpicon->linktext)) {
$alt = get_string('helpprefix2', '', trim($title, ". \t"));
} else {
$alt = get_string('helpwiththis');
}

$attributes = array('src'=>$src, 'alt'=>$alt, 'class'=>'iconhelp');
$output = html_writer::empty_tag('img', $attributes);

// add the link text if given
if (!empty($helpicon->linktext)) {
// the spacing has to be done through CSS
$output .= $helpicon->linktext;
}

// now create the link around it - we need https on loginhttps pages
$url = new moodle_url($CFG->httpswwwroot.'/help.php', array('component' => $helpicon->component, 'identifier' => $helpicon->identifier, 'lang'=>current_language()));

// note: this title is displayed only if JS is disabled, otherwise the link will have the new ajax tooltip
$title = get_string('helpprefix2', '', trim($title, ". \t"));

$attributes = array('href' => $url, 'title' => $title, 'aria-haspopup' => 'true', 'target'=>'_blank');
$output = html_writer::tag('a', $output, $attributes);

// and finally span
return html_writer::tag('span', $output, array('class' => 'helptooltip'));
return $this->render_from_template('core/help_icon', $helpicon->export_for_template($this));
}

/**
Expand Down
22 changes: 22 additions & 0 deletions lib/templates/help_icon.mustache
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{{!
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/>.
}}
{{!
Help icon.
}}
<span class="helptooltip">
<a href="{{url}}" title={{#quote}}{{title}}{{/quote}} aria-haspopup="true" target="_blank">{{#icon}}{{>core/pix_icon}}{{/icon}}{{#linktext}}{{.}}{{/linktext}}</a>
</span>

0 comments on commit a84eadb

Please sign in to comment.