From a84eadb88e0c23726f167d7e429aee5ce181e393 Mon Sep 17 00:00:00 2001 From: Frederic Massart Date: Wed, 17 Aug 2016 15:36:02 +0800 Subject: [PATCH] MDL-55701 output: Adding core template for help_icon 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 --- lib/outputcomponents.php | 11 +++++++++++ lib/outputrenderers.php | 34 +------------------------------- lib/templates/help_icon.mustache | 22 +++++++++++++++++++++ 3 files changed, 34 insertions(+), 33 deletions(-) create mode 100644 lib/templates/help_icon.mustache diff --git a/lib/outputcomponents.php b/lib/outputcomponents.php index 9acc0402824..71eafc2447e 100644 --- a/lib/outputcomponents.php +++ b/lib/outputcomponents.php @@ -499,6 +499,8 @@ class help_icon implements renderable, templatable { * @return array */ public function export_for_template(renderer_base $output) { + global $CFG; + $title = get_string($this->identifier, $this->component); if (empty($this->linktext)) { @@ -508,7 +510,16 @@ class help_icon implements renderable, templatable { } $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; diff --git a/lib/outputrenderers.php b/lib/outputrenderers.php index cd203f1784a..280e8004dc3 100644 --- a/lib/outputrenderers.php +++ b/lib/outputrenderers.php @@ -2412,39 +2412,7 @@ class core_renderer extends renderer_base { * @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)); } /** diff --git a/lib/templates/help_icon.mustache b/lib/templates/help_icon.mustache new file mode 100644 index 00000000000..d73c8c3201c --- /dev/null +++ b/lib/templates/help_icon.mustache @@ -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 . +}} +{{! + Help icon. +}} + + {{#icon}}{{>core/pix_icon}}{{/icon}}{{#linktext}}{{.}}{{/linktext}} +