2 // $Id: views_plugin_row.inc,v 1.3 2009/04/11 17:18:58 merlinofchaos Exp $
5 * Contains the base row style plugin.
9 * Default plugin to view a single row of a table. This is really just a wrapper around
12 * @ingroup views_row_plugins
14 class views_plugin_row extends views_plugin {
16 * Initialize the row plugin.
18 function init(&$view, &$display, $options = NULL) {
20 $this->display = &$display;
22 // Overlay incoming options on top of defaults
23 $this->unpack_options($this->options, isset($options) ? $options : $display->handler->get_option('row_options'));
26 function uses_fields() {
27 return !empty($this->definition['uses fields']);
31 function option_definition() {
32 $options = parent::option_definition();
33 if (isset($this->base_table)) {
34 $options['relationship'] = array('default' => 'none');
41 * Provide a form for setting options.
43 function options_form(&$form, &$form_state) {
44 if (isset($this->base_table)) {
45 $view = &$form_state['view'];
47 // A whole bunch of code to figure out what relationships are valid for
49 $relationships = $view->display_handler->get_option('relationships');
50 $relationship_options = array();
52 foreach ($relationships as $relationship) {
53 $relationship_handler = views_get_handler($relationship['table'], $relationship['field'], 'relationship');
55 // If this relationship is valid for this type, add it to the list.
56 $data = views_fetch_data($relationship['table']);
57 $base = $data[$relationship['field']]['relationship']['base'];
58 if ($base == $this->base_table) {
59 $relationship_handler->init($view, $relationship);
60 $relationship_options[$relationship['id']] = $relationship_handler->label();
64 if (!empty($relationship_options)) {
65 $relationship_options = array_merge(array('none' => t('Do not use a relationship')), $relationship_options);
66 $rel = empty($this->options['relationship']) ? 'none' : $this->options['relationship'];
67 if (empty($relationship_options[$rel])) {
68 // Pick the first relationship.
69 $rel = key($relationship_options);
72 $form['relationship'] = array(
74 '#title' => t('Relationship'),
75 '#options' => $relationship_options,
76 '#default_value' => $rel,
80 $form['relationship'] = array(
89 * Validate the options form.
91 function options_validate($form, &$form_state) { }
94 * Perform any necessary changes to the form values prior to storage.
95 * There is no need for this function to actually store the data.
97 function options_submit($form, &$form_state) { }
100 if (isset($this->base_table) && isset($this->options['relationship']) && isset($this->view->relationship[$this->options['relationship']])) {
101 $relationship = $this->view->relationship[$this->options['relationship']];
102 $this->field_alias = $this->view->query->add_field($relationship->alias, $this->base_field);
105 $this->field_alias = $this->view->base_field;
110 * Allow the style to do stuff before each row is rendered.
113 * The full array of results from the query.
115 function pre_render($result) { }
118 * Render a row object. This usually passes through to a theme template
119 * of some form, but not always.
121 function render($row) {
122 return theme($this->theme_functions(), $this->view, $this->options, $row, $this->field_alias);