Skip to content

Commit

Permalink
MDL-50084 pix: Updated pix to use the templatable interface
Browse files Browse the repository at this point in the history
  • Loading branch information
Dave Cooper committed May 4, 2015
1 parent 24a2bab commit eb42bb7
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 8 deletions.
20 changes: 19 additions & 1 deletion lib/outputcomponents.php
Expand Up @@ -503,7 +503,7 @@ public function diag_strings() {
* @package core
* @category output
*/
class pix_icon implements renderable {
class pix_icon implements renderable, templatable {

/**
* @var string The icon name
Expand Down Expand Up @@ -545,6 +545,24 @@ public function __construct($pix, $alt, $component='moodle', array $attributes =
unset($this->attributes['title']);
}
}

/**
* 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) {
$attributes = $this->attributes;
$attributes['src'] = $output->pix_url($this->pix, $this->component);
$templatecontext = array();
foreach ($attributes as $name => $value) {
$templatecontext[] = array('name' => $name, 'value' => $value);
}
$data = array('attributes' => $templatecontext);

return $data;
}
}

/**
Expand Down
9 changes: 2 additions & 7 deletions lib/outputrenderers.php
Expand Up @@ -2170,13 +2170,8 @@ public function pix_icon($pix, $alt, $component='moodle', array $attributes = nu
* @return string HTML fragment
*/
protected function render_pix_icon(pix_icon $icon) {
$attributes = $icon->attributes;
$attributes['src'] = $this->pix_url($icon->pix, $icon->component);
$templatecontext = array();
foreach ($attributes as $name => $value) {
$templatecontext[] = array('name' => $name, 'value' => $value);
}
return $this->render_from_template('core/pix_icon', array('attributes' => $templatecontext));
$data = $icon->export_for_template($this);
return $this->render_from_template('core/pix_icon', $data);
}

/**
Expand Down

0 comments on commit eb42bb7

Please sign in to comment.