0

Going to try and put this as simple as i can.

Lets say i have 2 Entity Reference Fields A and B.

A) Gives a list of Countries.

B) What ever country was selected in A should only display list of available State/Province's to that country

Example: Lets say i have a content type of Countries where i can save the country name in the title, then i also have a content type of state/province's where the state/province name is saved in the title with entity reference field where a county can be selected for that State/Province.

Lastly i have a content type user information, where a user can enter his/her name in the title, a entity reference field country and another entity reference field state/province. When the user select, lets say, USA as a country in the first entity reference field, the second one should only display a list of sates available in the USA.

Can something like this be done where the option of one Entity Reference field can be used as a filter for another entity reference? and if so, how can something like this be achieved? any and all help is much appreciated.

4
  • The module drupal.org/project/reference_option_limit is advertised to do this. But the project I was working on, this module caused more problems than solutions. Regardless, it is supposed to do exactly what you are wanting. If this doesn't work, ill post up a different solution.
    – iLLin
    Feb 14, 2017 at 21:47
  • Are you using Drupal 7 or 8? The module iLLin mentioned is for D7 only.
    – schlicki
    Feb 14, 2017 at 22:40
  • @iLLin thanks for pointing me to that module, but playing around with it also just gives me one error on to another... it does seem like a great module and there are some patches that i have tried as well, but seems like it needs more work. What else do you have that might work or point to something that i can try as well?
    – Duvan
    Feb 15, 2017 at 1:13
  • @schlicki i'm currently using D7
    – Duvan
    Feb 15, 2017 at 1:13

1 Answer 1

0

Found a categorically stunning module that does precisely what i needed over here https://www.drupal.org/project/ddf

Its simple to use as well. Install the module, enable Dynamic dependent fields and DDF Entity Reference modules after that.

Once that is done, go to your content type that contains the two or more enetity reference fields, using the example above that would mean editing content type user information. Now, go to manage fields, select edit on the entity refence field you want to be filtered, going back to the example again that would mean the state/province entity reference field, scroll down to the field settings section and on target type select node, on mode select the option Views: Filtered by an entity reference view with dynamic arguments, on views used to select the entities option choose the view that you have created for that entity reference - make sure that entity reference view has a contextual filter in it.

When all that is done, the last option is view arguments field and just below that the DDF module will give you a list of option that can be used as arguments to be passed to the entity reference views contextual filter... select one of them, in the example again, it would be something like {field_er_countries}.

Remember to save all your hard work and you should be good to go...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.