/[drupal]/contributions/modules/viewfield/theme/viewfield.theme.inc
ViewVC logotype

Diff of /contributions/modules/viewfield/theme/viewfield.theme.inc

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph | View Patch Patch

revision 1.2, Fri May 22 01:19:35 2009 UTC revision 1.3, Sun May 24 05:33:34 2009 UTC
# Line 1  Line 1 
1  <?php  <?php
2  // $Id: viewfield.theme.inc,v 1.1 2009/04/07 19:01:03 darrenoh Exp $  // $Id: viewfield.theme.inc,v 1.2 2009/05/22 01:19:35 darrenoh Exp $
3    
4  /**  /**
5   * @file   * @file
# Line 7  Line 7 
7   */   */
8    
9  /**  /**
10   * Theme function   * Return a themed view avoiding viewfield recursion.
  */  
 function theme_viewfield_formatter($element) {  
   _viewfield_load_view_info($element);  
   $node = $element['#node'];  
   if ($view_info = explode('|', $element['#item']['vname'])) {  
     $view_name = $view_info[0];  
     $display = $view_info[1];  
   }  
   else {  
     $view_name = $element['#item']['vname'];  
     $display = $element['#item']['display'];  
   }  
   $view_args = _viewfield_get_view_args($element['#item']['token_enabled'], $element['#item']['vargs'], $element['#node']);  
   return _viewfield_get_view_content($view_name, $view_args, $display, $node);  
 }  
   
 /**  
  * Load the view field data into the given $element if missing  
11   */   */
12  function _viewfield_load_view_info(&$element) {  function theme_viewfield_formatter_default($element) {
13    // Check if the node has been loaded.    global $_viewfield_stack;
14    if (!isset($element['#item']['token_enabled'])) {    // For safety's sake, we can only display 2 levels of viewfields.
15      static $fields;    if (count($_viewfield_stack) <= 2) {
16      $param_key = $element['#type_name'] .'-'. $element['#field_name'];      list($view_name, $display) = explode('|', $element['#item']['vname'], 2);
17      // Load field info.      $view_args = _viewfield_get_view_args($element['#item']['token_enabled'], $element['#item']['vargs'], $element['#node']);
18      if (!isset($fields[$param_key])) {      $node = $element['#node'];
19        module_load_include('inc', 'content', 'includes/content.crud');      // Need to prevent recursive views and node building, but don't need to do
20        $param = array('type_name' => $element['#type_name'], 'field_name' => $element['#field_name']);      // it on new node previews.
21        $fields[$param_key] = content_field_instance_read($param);      if ($node->nid) {
22      }        _viewfield_nodestack_push($node->nid);
23      $field = $fields[$param_key][0];      }
24      if ($element['#item']['vname'] == VIEWFIELD_DEFAULT_VNAME) {      array_unshift($view_args, $view_name, $display);
25        // We are in the default land here.      $output = call_user_func_array('views_embed_view', $view_args);
26        $element['#item'] = _viewfield_get_super_defaults($field);      // This node is "safe" again.
27        if ($node->nid) {
28          _viewfield_nodestack_pop();
29      }      }
30      $element['#item']['token_enabled'] = _viewfield_token_enabled($field);      return $output;
31    }    }
32  }  }
33    
# Line 106  function _viewfield_get_view_args($token Line 90  function _viewfield_get_view_args($token
90  }  }
91    
92  /**  /**
  * Return a themed view avoiding viewfield recursion.  
  */  
 function _viewfield_get_view_content($view_name, $view_args, $display, $node) {  
   global $_viewfield_stack;  
   global $user;  
   $output = '';  
   // For safety's sake, we can only display 2 levels of viewfields.  
   if (!empty($view_name) && count($_viewfield_stack) <= 2) {  
     // Need to prevent recursive views and node building, but don't need to do  
     // it on new node previews.  
     if ($node->nid) {  
       _viewfield_nodestack_push($node->nid);  
     }  
     array_unshift($view_args, $view_name, $display);  
     $output .= call_user_func_array('views_embed_view', $view_args);  
     // This node is "safe" again.  
     if ($node->nid) {  
       _viewfield_nodestack_pop();  
     }  
   }  
   return $output;  
 }  
   
 /**  
93   * Function for adding a node ID to the global stack of node IDs. This prevents   * Function for adding a node ID to the global stack of node IDs. This prevents
94   * us from recursively building a node, with a view, with the node, with the   * us from recursively building a node, with a view, with the node, with the
95   * view...   * view...

Legend:
Removed from v.1.2  
changed lines
  Added in v.1.3

  ViewVC Help
Powered by ViewVC 1.1.2