Hi Drupalers,

Ok so I have come accross a need for this in a project and have been trying to rack my brains on how to achieve it cleanly, maybe im overlooking something easy but the requirement is this:

Create a vocabulary with terms such as: Foods (Vocab) - Sandwhich, Pizza, Fruit, Burger (Terms)

Reference the term from a node such as: Storage (Content type) - Box 1, Box 2, Box3, Box 4 (Nodes)

Basically what I want to happen is a select list which is required and after a node is saved with a single term used it is no longer visible and available to other nodes created. Im thinking possibly a solution using views and entity reference but has anyone else done the same with another approach?

Thanks all!

Comments

vijaythummar’s picture

I think you can use this module: https://www.drupal.org/project/unique_field. It will give you validation message when you will assign same term to different node.

To remove term from the select list which is already assigned to another node you will require to customize code through hook_form_alter.

Hope it will help !

Thanks,
Vijay Thummar

GAMe’s picture

Hi,

Thanks for your response :-)

I have used that module before but not in conjunction with this. Im just trying out a few alternative things to see if I can make this happen. I will update this anyway with what I find so it may help someone else :-)

Cheers again

nevets’s picture

One possible approach is to use an entity reference field instead of a term reference field and try the Entity Reference Unique module

GAMe’s picture

Hi All,

Ok so here is what I did to get this working... actually didnt take much at all I just had to think about it for a min.

Created a view called Food Lookup based on Taxonomy which had a relationship to Taxonomy term: Content with term

Then filtered by Content: has taxonomy term EMPTY

the display was an Entity Reference also.

I then added an Entity reference field to the content type with select list chosen and told it to output the view.

Boom! easy does it.

Hope this helps someone else