I wanted to use a view for related content that would show a different list of nodes based on the value of a node reference for each node. The node reference in this case was for another node type that was used to group stories together. So I wanted to show related content that was some subset of the other stories in that grouping and I did not want to look at a list of all the hundreds of stories, just stories from that group. I think that view arguments are the best way to achieve this in general.

For this module, I found that I could make this happen by updating the calling of views_build_view in the functions _relatedcontent_form_view and _relatedcontent_track_finalize to look at the node, interrogate for the node reference and feed in that referenced 'nid' to the arguments array of views_build_view.

Is there a better way to achieve this functionality so that I don't need customize the module's code directly? Has anyone else done this?

CommentFileSizeAuthor
#1 relatedcontent_333656_pass_views_arg_1.patch798 bytesdooug
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

dooug’s picture

The original post is quite dated but I also had the same request with RelatedContent 6.x-1.0.

My solution was to hack the relatedcontent module... This is not a permanent solution/feature for the module. The patch includes my solution displayed here:

<?php
  //HACK - uses a node nid as an argument
  $args[] = $nid;
  $view->set_arguments($args);
?>

I used RelatedContent in conjunction with the SimpleNews module. I created a content type, Newsletter, that can have related content of another content type, Newsletter Items.

For my use, I passed the node id ($nid) of the node that has related content (Newsletter) as an argument. The related content nodes (Newsletter Items) have a node reference cck field (references the Newsletter node) that is used as the argument in the views that populate the related content tabs.

This requires a minor alteration to the module's code, I don't believe the module has the feature support to pass arguments to the views in the settings. I did not look at how this would be applied in the 5.x versions of RelatedContent.