Form filter fields working by filtering out data based off of control field
Taxonomy term with field of the control taxonomy term
View set up
View working by sorting out terms based on contextual filter
Form Filter Fields administration addition

This project is not covered by Drupal’s security advisory policy.

If you need a taxonomy field to be filtered based off of another taxonomy field's value, this module is for you. It is handled via Views.

I originally used Business Rules to accomplish the filtering but Business Rules only allowed filtering of one child when we needed multiple. That is all this module does where Business Rules has a lot of other things; not just dependent fields.

This module handles multiple dependencies so if you have a field that needs to filter multiple fields in your form, this module can handle that.

It is configured through an admin form where you specify the following:

  • Node or Media Type - Which content or media type the two fields are on.
  • Control Field - The field which controls the results of the Target Field.
  • Target Field - The field which changes values based off of the Control Field.
  • View - The view which handles the filtering. This view has a contextual filter (which should be your Control Field). The view handles the filtering so however you need to filter the Target Field, you do it with the view. The output of the view needs to be an HTML list of fields where you rewrite the result as tid|Option Name.

Features

  • Easy to maintain relationships
  • Relates taxonomy terms to other taxonomy terms in different vocabularies
  • Views controls the dependencies so it's easy to order
  • Works with select2, checkboxes, drop downs, radio buttons, etc.
  • Created two hooks to allow developers added functionality:
    • one to alter the form before it's processed
    • one to do other stuff on the event that something else needs to change when a field changes (ex. populate or manipulate a text field, clear a field's value, etc)
  • Works with node and media bundle entities

Installation & Setup

  • Install and enable the module
  • Establish relationships in taxonomy terms by creating a field on the dependent
    vocabulary. Add dependencies on terms.
    Taxonomy term with field of the control taxonomy term
  • Create a view which gets a term ID from the control vocabulary (contextual
    filter). Rewrite the results so it's in this kind of format:
    tid|Name
    ex. 45|Ball
    View set up
    View working by sorting out terms based on contextual filter
  • Go to /admin/config/content/form_filter_fields to add the relationship to your two fields.
    Form Filter Fields administration addition
  • Test and profit!

Related Modules

Known Issues

  • This module does not work with IEF (Inline Entity Form). Their way of creating forms is using a different object/class which is more complicated than Drupal's.

Project information

Releases