Views.module provides a textarea of PHP code for arguments, this patch adds just same feature for nodereference.module fields associated to views.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

DevElCuy’s picture

Here the patch with an screenshot for rounding the idea.

chrisroditis’s picture

Version: 5.x-1.x-dev » 6.x-2.x-dev
FileSize
8.83 KB

Here is the updated to 6.x-2.x-dev version, sorry I don'w know how to make a diff on...ermm...windows.

chrisroditis’s picture

FileSize
2.93 KB

Created a patch and fixed a logic error. Now the php textarea is given priority over the textfield, as per the original patch intentions.

pcambra’s picture

Works great, just what I needed, thanks develCuy & cristopher_skauss

arcane’s picture

Regarding #2, when I try to configure my nodereference, I get the error on D6:

Fatal error: Call to a member function get_option() on a non-object in /var/www/ccpresscred2.flash4play.com/public_html/sites/all/modules/views/includes/view.inc on line 1772

chrisroditis’s picture

views version?

chaloalvarezj’s picture

Tracking...

ntt’s picture

subscribing

ntt’s picture

When using PHP code to set the title of a CCK node, or setting the value of a computed field, the $node variable is avaible to be used... It would be good to have the same thing for setting the view arguments of node/userreference fields?

BWPanda’s picture

Status: Needs review » Reviewed & tested by the community
FileSize
2.7 KB

I've tested this module and it seems to work well!

I've updated the patch for the latest version of CCK 6.x-2.x-dev (dated 2009-Apr-24) and attached it below.
It'd be good to get this committed...

superstar’s picture

I have tested this patch on CCK 6.x-2.3 and it works correctly. Very useful.

Can we please have this committed asap.

zmove’s picture

/subscribre

Quite simple to patch, very low possibilites to break another functionnality, I think it can be commited.

kruser’s picture

subscribing

alvinet’s picture

subscribe

paganwinter’s picture

Subscribing...

superstar’s picture

Maintainers: could we please have this committed?

michaelhall’s picture

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

The patch works great for providing php arguments for the advanced node reference using a view, but I lose the ability to upload files to any custom content type in which the node reference php arguments are applied.

Is there any progress in providing a fix for the file upload issue caused by the current patch (Content-Construction-Kit_334121_10.patch)?

paganwinter’s picture

Subscribing...

nyl_auster’s picture

Subscribe

keyser79’s picture

could this be done for the userreference module as well?

DevElCuy’s picture

@keyser79 you pointed it right. We need this feature for all cck fields linked with views, is so handy and useful.

Blessings!

ifoundthetao’s picture

I can't seem to get this to work. I patched it, but I can't get any results from it. Any thoughts?

Here's my code:

return array('0'=>'4');

I have tried..

$arr = array();
$arr['first'] = 123;
return $arr['first'];

And as many different combinations as I could think of to try and get something to return.

Thanks!

ifoundthetao’s picture

I fixed it. It turns out I didn't apply the patch properly.

ccshannon’s picture

subscribe

Breakerandi’s picture

subscribe

SocialNicheGuru’s picture

I am a little confused. How can I pass the node author id as an argument?

I have a nodereference
I have assigned a view
I need to pass the node author of the current node to pull up all stories authored by the current nodes author.

On the node edit form for a node, is $node already known?

return array('0'=>$node->uid);

daggerhart’s picture

If this is on a node/add page, there isn't a node to pull an author from. You would need something like;

global $user;
return array('0'=>$user->uid);

The current user should also be the author of the added node.

If you're changing the author name when posting, you probably want a different solution. A view by itself could accept the $node->uid argument when presented on the node. You do this by changing the Validator to PHP Code in the view, and putting your current code in.

Did this answer the question?

superstar’s picture

Could we please have this committed. Thanks.

Jackl85’s picture

Title: Add PHP code textarea for views argument in nodereference.module fields » [Need Maintainers] Add PHP code textarea for 'views argument' in nodereference.module fields
Version: 6.x-2.5 » 6.x-2.6
Status: Reviewed & tested by the community » Patch (to be ported)
sarandi’s picture

subscribe

cliff_locus’s picture

subscribe

KarenS’s picture

Title: [Need Maintainers] Add PHP code textarea for 'views argument' in nodereference.module fields » Add PHP code textarea for 'views argument' in nodereference.module fields
Status: Patch (to be ported) » Needs work

The status 'to be ported' makes no sense here. It is not necessary to put [MAINTAINERS] into the title. #17 says there is a bug and no one addressed that issue.

Don't know if we want to support a new feature like this. Every place we allow people to add PHP code ends up creating lots of support issues from people who don't know how to use it. I'll let the other maintainers say what they think, but we are really trying not to add new features this late in the cycle.

markus_petrux’s picture

When you need to do something, there are often many ways to do it. Here we could have a way to do something that does not seem to add value compared to other ways to do it. Views provides hooks that can be used to alter the args, so I'm not sure this feature is really needed. I also think it may cause more headaches than benefit.

DevElCuy’s picture

I understand what is your feeling and I think that is good to postpone this feature request, perhaps will make sense later.

KarenS’s picture

Status: Needs work » Closed (won't fix)

If I mark it postponed that indicates to people who come upon the issue that there is an intention to add it later. At this point there is not, so I'm marking it won't fix.

If there is some reason to revisit this later (not sure what that would be) it can be reopened or a new issue opened.

webel’s picture

I am really interested in this feature.

@markus_petrux

Could you please give (or link to) an example showing how to filter nodes available for selection according to a node id ? For example, I want only child nodes of a given node to be available for selection. How do achieve the same as passing an %nid from the Views argument field ?

webel’s picture

I've figured out how to do what I need thanks to Advanced Help for views:

Action to take if argument is not present

..
Provide default

If no argument is given, a default argument can be selected. The method of choosing the default argument is selectable and pluggable.

Default arguments

..
Node ID from URL

This will attempt to find a Node ID from the URL, and is primarily useful for the Node: ID argument (though other arguments that use Node IDs, such as the CCK Node Reference argument, will find it useful too). For example, when visiting the path 'node/1' or 'node/1/edit' it will know that the '1' in that path is a node ID and use it.

Thanks views maintainers for this useful feature.

artsy.ca’s picture

This thread is indicative of a recurring issue in Drupal that keeps haunting us to this day:

Having to create custom node types that duplicate functionality when all we want is some simple variation.

Here is an example:

I have node type: "movie" with taxonomy: "genre": "horror", "action", "comedy" etc.

I have node type: "movie list" with a node reference to a list of movie nodes and also the same taxonomy as above.

I want movie list:horror to only display movie:horror in its node reference, likewise "action", "comedy", "etc"

If there were some way to pass a parameter to the view that is equal to the current node's taxonomy field, then I could have just two kinds of nodes.

This however is seeming to be impossible, so instead I have to create infinite content types, each identical except for one parameter.
The added complexity is enormous and it totally sucks. It leads to duplication not only here but also in the templates and menu items.

eme’s picture

For those who need this functionnality, it seems this can work will using Views arguments. I'm just testing this...

Example :
I want my user reference field to filter on a taxonomy term.
I pass this through the URL (node/add/page/taxo-term).

My node reference relies on a view with an argument taxonomy : terM

The you just put the default argument in PHP :

$arg=array();
$arg=explode('/', referer_uri());
return $arg[6];

Referer_uri just fetch the complete URL of your page, and the other just fetch the "taxo-term" part. You can adapt it of course.

Then the user reference field will be filtered.

clashar’s picture

subscribe

daggerhart’s picture

Just beating a dead horse here.

I needed this functionality again with a Content type within an OG Group. When creating a node within a group, I wanted the node reference to only see nodes in this Group.

Instead of using this patch, I was able to work around the issue with a views argument.

Argument: Organic Groups: Groups
Default if argument not present : PHP Code

if($_GET['gids']) {
  return implode(",", $_GET['gids']);
} else if ($group = og_get_group_context()) {
  return $group->nid;
}

Allow Multiple Arguments

I'm sure there are many drupalers that will tell me how terrible this is, but I don't see another way around it without applying this old patch.

Any other thoughts on how to accomplish this? Or is this a dead issue since the release of D7?

bsandor’s picture

I tested on userreference 6.x-2.9. It is working fine.

Wonderful feature.

------------------------
I run into a problem dough:
I'm on a node edit form. My code needs to get the node id that I'm editing so I make a query that gives me back an og id. This is what I'd like to send.
Anyways: I need to get the node id of an edit form with current php code.

I spent lots of time, couln't get it. Does somebody have an idea please?

Thanks in advance.

bsandor’s picture

I put these functions into my code and none of them worked:
og_get_group_context()
arg(1)

Is it related to this module or to a node edit form?

When I set these manually (equal to my group id OR argument 1) , the php code sends correct arguments to the view.

Why this php code can't get the output of these functions? Any idea?

Gomu’s picture

Patch in comment #3 worked fine. Thanks.