does not pass view to node

hefox - October 1, 2009 - 15:42
Project:Views Tabs
Version:6.x-1.x-dev
Component:Code
Category:bug report
Priority:normal
Assigned:Unassigned
Status:active
Description

the view is not passed to node which leads to view based things like not adding node-view-VIEWNAME.tpl.php to the template_file suggestions.

easy enough fix:

<?php
        $node
= node_load($row->nid);
         
$node->view = $this->view; // add this
       
$content = node_view($node, $this->row_plugin->options['teaser'], FALSE, $this->row_plugin->options['links']);
       
$tab = $node->title;
?>

#1

nedjo - October 1, 2009 - 15:48

Thanks, I'll have a look at this.

#2

hefox - October 1, 2009 - 15:55

Here, some more alterations; I believe the views api has changed since the module was last updated, ie no $options['teaser']. Attached is a patch

<?php
     
else {
       
$node = node_load($row->nid);
       
$node->view = $this->view;
       
$options = $this->row_plugin->options;
       
$node->build_mode = ($options['build_mode'] == 'teaser' || $options['build_mode'] == 'full') ? NODE_BUILD_NORMAL :        $options['build_mode'];

       
$content = node_view($node, $options['build_mode'] == 'teaser', FALSE, $options['links']);
       
$tab = $node->title;
        if (!empty(
$options['comments']) && function_exists('comment_render')) {
           
$content .= comment_render($node);
        }

      }
?>

These are based on template_preprocess_views_view_row_node in views/modules/node.views.inc

AttachmentSize
views_tabs_options.patch 983 bytes

#3

Scott Reynolds - October 28, 2009 - 21:43

Instead can we use the row plugin stuff. Looking at the code, I think you can just do

<?php
function render() {
$this->definition['theme'] = $this->row_plugin->definition['theme'];
   
// Create empty tabset to build up
    
   
$tabset = array(
     
'#type' => 'tabset',
    );

    if (
$this->row_plugin->definition['uses fields']) {
     
// Get a list of the available fields. 
     
$_fields = array_keys($this->view->field);
   
     
// If title is the tab, and there is no title - assign the first field
     
if (!$this->view->field['title']
            &&
$this->options['tab_field'] == 'title') {
       
$this->options['tab_field'] = $_fields[0];
      }
     
$tab_field = $this->view->field[$this->options['tab_field']]->field_alias;
    }
  
$content = parent::render();
  if (!
$tabset[$tab]) {
       
$tabset[$tab] = array(
         
'#type' => 'tabpage',
         
'#content' => $content,
         
'#title' => $tab,
         
'#attributes' => array('class' => 'node-'. $row->nid),
        );
      }
    }
    return
tabs_render($tabset);
}
?>

This way you can use whatever row style you have. So the node row style with all the settings, without having to use that patch. All row style options will be respected. Instead of just node, or field options.

I would also look int ot removing that class 'node-' . $row-nid.

#4

hefox - October 28, 2009 - 22:27

Does this method work for you?Could you provide a patch? I'm having trouble figuring out the how this would work.

or rather what is most confusing me is then render() function goes through each row; your example is only using one row, etc... I can't see how parent::render would work in this case since it returns all rows rendered, so the entire view would end up as one tab page, which isn't the current functionality of this module.

I do agree that should use some of the parent render's code to remove the problems, but how exactly I haven't looked into since still need to provide the tab title from node (title) and fields (some field) or whatever other plugin (would need to define how to get titles for each, which seems like it'll get complicated).

#5

jdwfly - November 10, 2009 - 22:42

I went ahead and incorporated this code into my patch to fix the module for views 2.7.

#626170: Not working with Views 6.2.7?

 
 

Drupal is a registered trademark of Dries Buytaert.