cck variables get printed as null in Drupal 5 view

  1. //in template.php----------------------------
  2.  
  3.  
  4. function phptemplate_views_view_list_promotion_box($view, $nodes, $type) {
  5.   /*
  6.   $fields = _views_get_fields();
  7.   drupal_set_message('<PRE>phptemplate_views_view_list_promotion_box(): $fields: '.print_r($fields, 1).'</PRE>');
  8.   drupal_set_message('<PRE>phptemplate_views_view_list_promotion_box(): $view: '.print_r($view, 1).'</PRE>');
  9.   drupal_set_message('<PRE>phptemplate_views_view_list_promotion_box(): $nodes: '.print_r($nodes, 1).'</PRE>');
  10.   drupal_set_message('<PRE>phptemplate_views_view_list_promotion_box(): $type: '.print_r($type, 1).'</PRE>');
  11.   */
  12.   $taken = array();
  13.  
  14.   // Group our nodes
  15.   $set = array();
  16.   foreach($nodes as $node)
  17.   {
  18.    $set[$node->node_title][] = $node;
  19.   }
  20.  
  21.   // Set up the fields in nicely named chunks.
  22.   foreach ($view->field as $id => $field) {
  23.     $field_name = $field['field'];
  24.     if (isset($taken[$field_name])) {
  25.       $field_name = $field['queryname'];
  26.     }
  27.     $taken[$field_name] = true;
  28.     $field_names[$id] = $field_name;
  29.   }
  30.  
  31.   // Set up some variables that won't change.
  32.   $base_vars = array(
  33.     'view' => $view,
  34.     'view_type' => $type,
  35.   );
  36.  
  37.   $output = "{\n";
  38.   $j = 0;
  39.   foreach ($set as $label => $nodes)
  40.   {
  41.    if($j > 0)
  42.    {
  43.     $output .= ",\n";
  44.    }
  45.    ++$j;
  46.    $items = array();
  47.    foreach ($nodes as $i => $node)
  48.    {
  49.     $vars = $base_vars;
  50.     $vars['node'] = $node;
  51.     $vars['count'] = $i;
  52.     $vars['stripe'] = $i % 2 ? 'even' : 'odd';
  53.     foreach ($view->field as $id => $field)
  54.     {
  55.      $name = $field_names[$id];
  56.      $vars[$name] = views_theme_field('views_handle_field', $field['queryname'], $fields, $field, $node, $view);
  57.      if (isset($field['label']))
  58.      {
  59.       $vars[$name . '_label'] = $field['label'];
  60.      }
  61.     }
  62.     $items[] = _phptemplate_callback('views-list-promotion_box', $vars);
  63.    }
  64.    if ($items)
  65.    {
  66.     //print('<PRE> '); var_dump($items); print(' </PRE>');
  67.     //print('<PRE> '); var_dump($label); print(' </PRE>');
  68.     $output .= '"'.$j.'": '.theme('promotion_box_item_list', $items, $label);
  69.    }
  70.   }
  71.   $output .= "}\n";
  72.   return $output;
  73. }
  74.  
  75. function phptemplate_promotion_box_item_list($items = array(), $title = NULL, $type = 'ul', $attributes = NULL) {
  76.   $output = '';
  77.  
  78.   if (!empty($items)) {
  79.     $output .= "\n";
  80.     foreach ($items as $item) {
  81.       $attributes = array();
  82.       $children = array();
  83.       if (is_array($item)) {
  84.         foreach ($item as $key => $value) {
  85.           if ($key == 'data') {
  86.             $data = $value;
  87.           }
  88.           elseif ($key == 'children') {
  89.             $children = $value;
  90.           }
  91.           else {
  92.             $attributes[$key] = $value;
  93.           }
  94.         }
  95.       }
  96.       else {
  97.         $data = $item;
  98.       }
  99.       if (count($children) > 0) {
  100.         $data .= phptemplate_promotion_box_item_list($children, NULL, $type, $attributes); // Render nested list
  101.       }
  102.       $output .= $data ;
  103.     }
  104.   }
  105.   return $output;
  106. }
  107.  
  108. //end of template.php---------------------------------------
  109. //in views-list-promotion_box.tpl.php--------------------------
  110. <?php
  111.  drupal_add_css(path_to_theme() .'/views-list-promotion_box.css');
  112.  print json_encode
  113.  (
  114.   (
  115.    'title' => $title,
  116.    'field_promo_category_value' => $field_promo_category_value,
  117.    'body' => $body,
  118.    'field_promo_article_nid' => $field_promo_article_nid,
  119.    'field_promo_url_value' => $field_promo_url_value,
  120.    'field_promo_image_fid' => $field_promo_image_fid
  121.   )
  122.  );
  123. ?>
  124. //end of views-list-promotion_box.tpl.php--------------------------
  125. //old views-list-promotion_box.tpl.php---------------------------------------------
  126. <?php
  127. /**
  128.  * views template to output one 'row' of a view.
  129.  * This code was generated by the views theming wizard
  130.  * Date: Wed, 2008-06-04 10:23
  131.  * View: promotion_box
  132.  *
  133.  * Variables available:
  134.  * $view -- the entire view object. Important parts of this object are
  135.  *   promotion_box, .
  136.  * $view_type -- The type of the view. Probably 'page' or 'block' but could
  137.  *   also be 'embed' or other string passed in from a custom view creator.
  138.  * $node -- the raw data. This is not a real node object, but will contain
  139.  *   the nid as well as other support fields that might be necessary.
  140.  * $count -- the current row in the view (not TOTAL but for this page) starting
  141.  *   from 0.
  142.  * $stripe -- 'odd' or 'even', alternating. * $title -- Display the title of the node.
  143.  * $title_label -- The assigned label for $title
  144.  * $field_promo_category_value --
  145.  * $field_promo_category_value_label -- The assigned label for $field_promo_category_value
  146.  * $body -- Display the Main Content.
  147.  * $body_label -- The assigned label for $body
  148.  * $field_promo_article_nid --
  149.  * $field_promo_article_nid_label -- The assigned label for $field_promo_article_nid
  150.  * $field_promo_url_value --
  151.  * $field_promo_url_value_label -- The assigned label for $field_promo_url_value
  152.  * $field_promo_image_fid --
  153.  * $field_promo_image_fid_label -- The assigned label for $field_promo_image_fid
  154.  *
  155.  * This function goes in your views-list-promotion_box.tpl.php file
  156.  */
  157.  
  158.  
  159.  //now we add the stylesheet...
  160.   drupal_add_css(path_to_theme() .'/views-list-promotion_box.css');
  161.  
  162.   ?>
  163. <div class="view-label view-field-title">
  164.   <?php print $title_label ?>
  165. </div>
  166. <div class="view-field view-data-title">
  167.   <?php print $title?>
  168. </div>
  169.  
  170. <div class="view-label view-field-field-promo-category-value">
  171.   <?php print $field_promo_category_value_label ?>
  172. </div>
  173. <div class="view-field view-data-field-promo-category-value">
  174.   <?php print $field_promo_category_value?>
  175. </div>
  176.  
  177. <div class="view-label view-field-body">
  178.   <?php print $body_label ?>
  179. </div>
  180. <div class="view-field view-data-body">
  181.   <?php print $body?>
  182. </div>
  183.  
  184. <div class="view-label view-field-field-promo-article-nid">
  185.   <?php print $field_promo_article_nid_label ?>
  186. </div>
  187. <div class="view-field view-data-field-promo-article-nid">
  188.   <?php print $field_promo_article_nid?>
  189. </div>
  190.  
  191. <div class="view-label view-field-field-promo-url-value">
  192.   <?php print $field_promo_url_value_label ?>
  193. </div>
  194. <div class="view-field view-data-field-promo-url-value">
  195.   <?php print $field_promo_url_value?>
  196. </div>
  197.  
  198. <div class="view-label view-field-field-promo-image-fid">
  199.   <?php print $field_promo_image_fid_label ?>
  200. </div>
  201. <div class="view-field view-data-field-promo-image-fid">
  202.   <?php print $field_promo_image_fid?>
  203. </div>
  204. //end of old views-list-promotion_box.tpl.php