Download & Extend

Node reference, using the advance view option, arguments are too limited

Project:Content Construction Kit (CCK)
Version:6.x-2.x-dev
Component:nodereference.module
Category:feature request
Priority:normal
Assigned:Unassigned
Status:closed (duplicate)

Issue Summary

My scenario is :

Content type
Story (has a node_reference field, type Photo) | Photo (has a image cck field)

When editing a story, I'd like the node reference to be able to choose a photo which owned by the same author of the story.

So I create a view, photo_reference, which basically takes an argument: uid, and has one field: title.

But when I set the node_reference setting it's not possible to make the uid argument be passed dynamically.

It seems that you can only pass a defined argument to the view, and not able to use the view's default argument.
In my case I actually write a PHP default argument in the view, but it's never called, so I have to impelement hook_views_pre_view to set the argument.

<?php
// hook_views_pre_view
function hook_views_pre_view(&$view, $display_id = 'default', $args = array()) {
  if (
$view->name == 'photo_reference' && !$args) {
   
// set the default arguments to be the node's author,
    // then the photo_reference can get the photos owned by this user,
    // and put them in the node reference selecton
   
$nid = 0;
   
$path = explode('/', $_GET['q']);
    if(
sizeof($path) == 3 && $path[0] == 'node' && is_numeric($path[1]) && $path[2] == 'edit' ) {
     
$nid = $path[1];
    }
    if (
$nid) { // get node from url
     
$node = node_load($nid);
     
$uid = $node->uid;
    }
    else{
// may be new node, use the logged user id
     
global $user;
     
$uid = $user->uid;
    }
   
$view->set_arguments(array($uid));
  }
}
?>

The above code is basically ok to fit in a views default argument. If the node_reference can load default argument when the argument field is empty, it will be great.

Comments

#1

Thanks for the code, I haven't tried it but I have the same requirement... to the use the view's default argument handling code when none is specified by the node reference argument field (otherwise you're stuck typing in a static argument - no good)

#2

Category:support request» feature request

#3

I think it will be great to use tokens in View arguments field as in pathauto settings

Also in view filter you can use option

User: Current
Filter the view to the currently logged in user.

AttachmentSize
tokenuid.PNG 9.39 KB

#4

Version:6.x-2.1» 6.x-2.x-dev

subscribing, would be pretty cool.

#5

#6

Status:active» closed (duplicate)

Long standing request :-) There's already an issue with a patch for that, maybe two. The main reason it's not in is that no-one dare to review it enough to set it RTBC - well I'm also not completely sold on the case of node *creation* form (we don't have a node yet, thus no node context).
See http://drupal.org/node/196518#comment-984025

nobody click here