From 01d9631666055ed100cc6a709e5e7584d9e1d454 Mon Sep 17 00:00:00 2001
From: Marco Villegas <marvil07@gmail.com>
Date: Thu, 11 Nov 2010 03:26:07 -0500
Subject: [PATCH] #968630: Let widgets modify template variables.

---
 WIDGETAPI.txt |    9 +++++++++
 vud.theme.inc |    4 ++++
 2 files changed, 13 insertions(+), 0 deletions(-)

diff --git WIDGETAPI.txt WIDGETAPI.txt
index 797ab54..9fe986d 100644
--- WIDGETAPI.txt
+++ WIDGETAPI.txt
@@ -116,6 +116,7 @@ function MODULEORTHEMENAME_WIDGETNAME_vud_widgets() {
     'title' => t('Default'),
     'widget template' => 'widget',
     'votes template' => 'votes',
+    'alter template variables' => 'callback_function'
   );
 }
 ----
@@ -125,6 +126,14 @@ widget.tpl.php and the 'votes template' line if you are including a
 votes.tpl.php. If you want the template named differently, the value of
 this line will set that.
 +
+You should include the 'alter template variables' line if you need to
+modify variables that are passed to the widget templates. Naturally, you
+need to replace the 'callback_function' with the name of the callback
+function you want to use. The signature of the function is
+`callback_function($template_type, &$variables)` where `$template_type`
+can be 'widget' or 'votes' and `$variables` is a typically theme
+variables array.
++
 If you create a WIDGETNAME.css file this will automatically be included.
 If you want this file to be different, add
 +
diff --git vud.theme.inc vud.theme.inc
index 0cd810f..36ed3f4 100644
--- vud.theme.inc
+++ vud.theme.inc
@@ -94,6 +94,10 @@ function vud_pseudo_theming($vote_entity, $template_type, $plugin, &$variables)
   // let modules modify variables passed to the template
   $variables_type = 'vud_' . $template_type . '_template_variables';
   drupal_alter($variables_type, $variables);
+  // let widget modify variables passed to the template
+  if ($function = ctools_plugin_get_function($plugin, 'alter template variables')) {
+    $function($template_type, $variables);
+  }
 
   // and then provide template suggestions by hand
   $suggestions = module_invoke('vud_' . $vote_entity, 'template_suggestions', $template_type, $plugin, $variables['content_id']);
-- 
1.7.2.3

