Filter Entity reference based on attribute Here's my situation: I have a "Project" content type. I want to be able to add employees to a project based on their role with a select or multi-select drop down widget with unlimited number of values. So I can add multiple people with different roles.

I would like to be able to choose a Role first - say a "designer" - and then have the drop down for the entity reference only show just the roles for designers.

Project
  --&gt; choose Role "designer"
  --&gt; choose designer "John Doe"
  Add next person
  --&gt; choose Role "??"
  --&gt; choose person "??"


What are possible ways to do this?
The best way I found offering a very high amount of flexibility is to combine the two following components:


The Dynamic Dependent Fields (DDF) module takes in charge the relation between the other fields composing your form and your Entity Reference field.

Concretely, it will add a new mode for the entity selection, "Views: Filter by an entity reference view with dynamic argument", which allows you to dynamically pass the value of one or several other fields of your edit form as contextual filters to a view.

The magic here is that the values proposed by your Entity Reference is dynamically updated upon modification of the controller fields content (JavaScript).

The only limitations I encountered with this module is that it does not support autocomplete fields as the controlee Entity Reference fields, drop-down lists must be used instead. Moreover, DDF does not take into account programmatically set default values for the controller fields, however I submitted a patch solving this.
A patch for Entity Reference (currently in RTBC status) adds the possibility to use tokens now as contextual filter for the views and complement very well the above mentioned DDF module.

For instance, this patch allows very easily to exclude the current entity from the Entity Reference available choices.


Associating the two modules let your Entity Reference fields available values to be generated by a View taking into account both tokens and other fields values. Hard to get more flexibility !