Problem/Motivation

When the controlling field is an entity reference (for example a taxonomy term shown as radio buttons), conditions can only be written against the entity ID. The widget mode stores the target_id, and the AND/OR/XOR/NOT and Regular expression modes are compared with the submitted value, which is also the ID. A regex such as ^(Customer|Partner)$ never matches, because the browser submits 29, not "Customer".

This is a problem when environments don't have the same IDs. Dependency settings are exported with config, but terms are content and are often created per environment (deploy hook, migration, editors). The same term can have a different ID on local, stage and production, so a condition saved as "term ID 29" points to the wrong term, or none, on other environments. The dependent fields silently stay hidden.

Related: #2715655 (7.x, machine name instead of tid), #2373347 (7.x, UUIDs, closed as outdated), #3077694.

Steps to reproduce

  1. Add a single-value term reference field (radio buttons widget) with terms Customer, Partner, Other.
  2. Add a second field with a dependency on it: Visible, condition Value, regex ^(Customer|Partner)$.
  3. The second field never appears. Using "Insert value from widget" works, but stores the term ID, which differs between environments.

Proposed resolution

Add a "Label" values-set option (one label per line). When the form is built, the radio/checkbox and select handlers map each label to the matching key in the field's #options and build the #states from those keys. evaluateDependency() does the same on the server. Labels are stored, not IDs, so the config works on every environment.

To decide: translated or untranslated label, and behavior when a label matches no option.

Remaining tasks

  • Agree on the approach.
  • Implement handlers and server-side evaluation.
  • Add kernel and FunctionalJavascript tests.

User interface changes

One new choice in the values input mode selector, with a textarea for labels.

API changes

One new constant on ConditionalFieldsInterface.

Data model changes

None expected beyond a new allowed values_set value (to be confirmed against the config schema).

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

carolpettirossi created an issue. See original summary.

carolpettirossi’s picture

Issue summary: View changes