jumper
jumper

Reputation: 165

Restrict which nodes can be referenced

Is it possible to restrict the nodes in a node reference field to nodes, which were created by the current user?

Imagine one node of the type x & several nodes of the type y. Node x has an unlimited number of node reference field to nodes of the type y.

UPDATE:

An user has to reference several experiences to show his qualification for a certain project. All of his experiences are nodes of the type "project_experience" which has to fields:
1. one project (node reference to content type "project")
2. one description of the function and experience in this project.

When creating a node "project_application" the user should decide which of his experiences/projects are specific to the project he is applying to.

Upvotes: 0

Views: 1202

Answers (2)

gilzero
gilzero

Reputation: 1902

Here is what I did for a temporary solution (very ugly solution) while waiting for References release Advanced Node Reference Views function.

Create a patch for node_reference.module (version: references-7.x-2.x-dev, 2011-Mar-27)

find the function _node_reference_potential_references_standard,

add this after declaration of the function:

global $user;
$uid = $user->uid;

after this line: $node_type_alias = $query->addField('n', 'type', 'node_type'); add:

$node_uid_alias  = $query->addField('n', 'uid',  'node_uid');

after this line: $query->condition('n.type', $field['settings']['referenceable_types'], 'IN'); add:

$query->condition('n.uid', $uid, '=');

Again, this isn't a good solution, just in case you might be interested.

Upvotes: 0

junedkazi
junedkazi

Reputation: 519

Yes it is possible to do that by creating a view which has an argument to the currently logged in user. The view should display all the nodes of the node reference type.

In the node reference field you can select the view.

http://drupal.org/node/289738 should just give you an insight as to how views can be used with node reference field.

Upvotes: 1

Related Questions