The $view object

A quick overview

drowlflood - October 3, 2007 - 05:57

For my own edification, I created a dummy View Type to print out the contents of the $view object with the following code:

<?php
/**
*  Implementation of hook_views_style_plugins()
*  Adds a callback entry to the Page/Block 'View Type' dropdowns
*/
function example_views_style_plugins() {
 
$styles = array();
 
$styles['example'] = array(
     
'name' => 'Example',
     
'theme' => 'example_view',
     
'validate' => 'views_ui_plugin_validate_list',
     
'needs_fields' => true,
     
// 'weight' => 10,
 
);
  return
$styles;
}

/**
*  Theme callback for example_views_style_plugins()
*/
function theme_example_view($view, $nodes, $type) {
  return
print_r($view);
}
?>

Basically, it looks like this:

stdClass Object (
  [vid] => 1
  [name] => Example View
  [description] => This is an example view
  ... The first 30 or so key-value pairs are pulled directly from the "view_view" table. 
  ... Take a look at table definition in phpMyAdmin or the like for more detail.
  ...
  [sort] => Array (
      [0] => Array (
          [vid] => 1
          ... Likewise, each of these keyed arrays corresponds to records in the "view_sort" table,
          ... with the addition of the following 'id' key:
          ...
          [id] => node_data_field_examplefield.field_examplefield_value
      )
  )
  [argument] => Array ( Array (
      [0] => Array (
          [vid] => 1
          ... Key-value pairs pulled from the "view_argument" table
          ...
      )
  )
  [field] => Array (
      [0] => Array (
          [vid] => 1
          ... Key-value pairs pulled from the "view_tablefield" table,
          ... with the addition of the following three fields added programatically:
          ...
          [fullname] => node_data_field_examplefield.field_examplefield_fid
          [id] => node_data_field_examplefield.field_examplefield_fid
          [queryname] => node_data_field_examplefield_field_examplefield_fid
      )
  )
  [filter] => Array (
      ... Records from "view_filter"
  )
  [exposed_filter] => Array (
      ... Records from "view_exposed_filter"
  )
);

So it seems as if the $views object is really just there to link these tables together and leaves the heavy lifting of actually getting the records' values to the various "_views_get_xxx" functions contained in views_cache.inc.

 
 

Drupal is a registered trademark of Dries Buytaert.