From eb42bb7e83891896d685aebe4cab9888a7414048 Mon Sep 17 00:00:00 2001 From: Dave Cooper Date: Mon, 4 May 2015 14:38:16 +0800 Subject: [PATCH] MDL-50084 pix: Updated pix to use the templatable interface --- lib/outputcomponents.php | 20 +++++++++++++++++++- lib/outputrenderers.php | 9 ++------- 2 files changed, 21 insertions(+), 8 deletions(-) diff --git a/lib/outputcomponents.php b/lib/outputcomponents.php index fe827558d36..4efe670aafd 100644 --- a/lib/outputcomponents.php +++ b/lib/outputcomponents.php @@ -503,7 +503,7 @@ class help_icon implements renderable { * @package core * @category output */ -class pix_icon implements renderable { +class pix_icon implements renderable, templatable { /** * @var string The icon name @@ -545,6 +545,24 @@ class pix_icon implements renderable { 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; + } } /** diff --git a/lib/outputrenderers.php b/lib/outputrenderers.php index 1df85acd5db..c185cdcd731 100644 --- a/lib/outputrenderers.php +++ b/lib/outputrenderers.php @@ -2170,13 +2170,8 @@ class core_renderer extends renderer_base { * @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); } /**