Skip to content

Commit

Permalink
MDL-55462 output: Make help_icon templatable
Browse files Browse the repository at this point in the history
Render it with a template in the new theme.

Part of MDL-55071
  • Loading branch information
Damyon Wiese authored and danpoltawski committed Sep 23, 2016
1 parent a26d57e commit b7e9526
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 1 deletion.
24 changes: 23 additions & 1 deletion lib/outputcomponents.php
Original file line number Diff line number Diff line change
Expand Up @@ -447,7 +447,7 @@ public function get_url(moodle_page $page, renderer_base $renderer = null) {
* @package core
* @category output
*/
class help_icon implements renderable {
class help_icon implements renderable, templatable {

/**
* @var string lang pack identifier (without the "_help" suffix),
Expand Down Expand Up @@ -491,6 +491,28 @@ public function diag_strings() {
debugging("Help contents string does not exist: [{$this->identifier}_help, $this->component]");
}
}

/**
* Export this data so it can be used as the context for a mustache template.
*
* @param renderer_base $output Used to do a final render of any components that need to be rendered for export.
* @return array
*/
public function export_for_template(renderer_base $output) {
$title = get_string($this->identifier, $this->component);

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

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

$data->ltr = !right_to_left();
return $data;
}
}


Expand Down
11 changes: 11 additions & 0 deletions theme/noname/classes/output/core_renderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
use moodle_url;
use preferences_groups;
use action_menu;
use help_icon;

defined('MOODLE_INTERNAL') || die;

Expand Down Expand Up @@ -261,4 +262,14 @@ public function render_action_menu(action_menu $menu) {
return $this->render_from_template('core/action_menu', $menu);
}

/**
* Implementation of user image rendering.
*
* @param help_icon $helpicon A help icon instance
* @return string HTML fragment
*/
protected function render_help_icon(help_icon $helpicon) {
$context = $helpicon->export_for_template($this);
return $this->render_from_template('core/help_icon', $context);
}
}
6 changes: 6 additions & 0 deletions theme/noname/templates/core/help_icon.mustache
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<button class="btn btn-link p-a-0"
data-container="body" data-toggle="popover"
data-placement="{{#ltr}}right{{/ltr}}{{^ltr}}left{{/ltr}}" data-content="{{text}} {{completedoclink}}"
data-html="true" tabindex="0" data-trigger="click">
{{#pix}}help, core, {{alt}}{{/pix}}
</button>

0 comments on commit b7e9526

Please sign in to comment.