Hi everyone,

I have a content type A and two other content type B and C. Every content B and C are associated to one content A thanks to a Reference Node field (module Reference). Now and in addition to this, I would like every content B to be also linked to a content C, but only to a C-content linked to same A-content as the current B-content...

When creating or upgrading a B-content, the user must choose a field Reference Node of Content Type C and I would like to restrict the available choices to only C-content linked to same A-content as the current B. Indeed, using a field Node Reference to Content Type C, every C-nodes will be proposed to the user, and I would like to restrict this list to only the specific nodes (to avoid errors from users ...).

Is it possible with Drupal (7.x) ? Maybe I'm totally unclear, in that case : sorry I'll do my best to be clearer :-)

Thanks in advance !!

Edit:
I found the module Reference option limit from Joachim and it works great !
Note that, to link the nodes with a field, module Entity Reference must be used instead of References. This last one is not taken into account by Reference Option Limit (see this post).

Comments

nevets’s picture

You can use view to make the list of possible nodes. So my initial attempt would be to make a view that lists content of type 'C', add a relationship on the entity reference field, and now change the listed fields to use the relationship.

Thoster’s picture

Hi and thank you for your answer,

That doesn't seem to work or I didn't do it well :-/
The proposed list is still containing every content type C...

Say field_A and field_C are respectively the fields referencing a content type A and C.

- I created a View view_C searching content type C
- I created a View Display "References"
- I added a Relationship on this display for : "Content A (field_A)"
- I set "require this relationship"
- Then in content type B, the field field_C (that references a C-type), the list of selection is made thanks to the view (VIEWS - NODES THAT CAN BE REFERENCED)

Should I put something as argument to the view ?

Thank you again.

nevets’s picture

First thought was wrong, lets try

Create a view that has an argument on the entity reference field for content type C.

Thoster’s picture

well, how do you do that ? (sorry, I'm new to drupal ... :-/)

Is it adding a "contextual filter" on "content: field_C" ?
If so, then I can chose "Relationship" with "field_A" or not and what to do in case...
I tried with/without relationship, but still not working: while choosing a value for "field_A", the list of choice for field_C does not change.

Btw, I'm wondering if the view can be "recomputed" by changing the field "field_A" (referencing B to A) (dynamically) ?

thanks again ^^

Thoster’s picture

I found the module Reference option limit from Joachim and it works great !
Note that, to link the nodes with a field, module Entity Reference must be used instead of References. This last one is not taken into account by Reference Option Limit (see this post).