Add validator tokens to condition handling

Created on 13 June 2018, over 6 years ago
Updated 15 July 2023, over 1 year ago

Problem/Motivation

Currently the "Replacement patterns" on the validator configuration list the "local" tokens:

  • [entity-type] == Machine name of entity type
  • [bundle] == Machine name of bundle
  • [field-name] == User readable name of current field
  • [value] == Current value to be validated on

These are currently only available for the error message.
However, it would be handy to have the value available for the conditions too.

You might wonder why - imagine this scenario:
You've three fields x, a and b.
One of a or b is required if x is "enabled".
You can achieve that if you use the validator "Require at least one of several fields" and a conditional validation.
Add all fields to the same "Require at least one of several fields" group.
But configure the conditional validation of x so that it only validates if the value is not equal to "enabled".
This means if x is set to "enabled" it will never validate in the group and a or b are required.
But if x is set to something different it will validated and that for the whole group making a & b optional.

This works nicely with conditional_fields which allows you to show / hide fields based on configured rules.

Proposed resolution

Run the replacement of the "local" tokens before the token_replace() code that's already in place.

Remaining tasks

Reviews needed.

User interface changes

Changed text in admin UI.

API changes

None.

Data model changes

None.

Feature request
Status

Needs review

Version

2.0

Component

Code

Created by

🇨🇭Switzerland das-peter

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • First commit to issue fork.
Production build 0.71.5 2024