Provide a ConditionsFormTrait or form element for conditions

Created on 23 October 2024, 7 months ago

Problem/Motivation

Just had the need to implement form with conditions (from Condition Plugins) for two different module settings pages.
I think needing conditions for settings forms and entity forms isn't a very rare case and most of us have seen them already (or someone implementing the conditions by hand, as they weren't aware it exists or how to use them - indeed it's not easy to find documentation but that's another topic).

Typical forms where such conditions are useful:

  • Core Blocks
  • Tracking / analytics integration modules to control visibility of the hook_page_attachments() added libraries (there are many and most of them implement the conditions not using Condition Plugins!)
  • Context module
  • Asset injector module
  • ...

Looking for existing implementations of form using conditions, I found
https://git.drupalcode.org/project/core_extend/-/blob/8.x-1.x/src/Form/C...
in the old https://www.drupal.org/project/core_extend module.

And I think that's an excellent basic idea for core to unify and simplify use of conditions in forms.

So the question is, if a trait is the best way to provide an easier integration (I think so) or if a form element would even make sense. Thinking about that, I think a form element would be hard to configure, harder to individualize and as conditions are typically displayed as vertical tabs, I think a form element would be untypical.

Steps to reproduce

Implement a Condition Plugin form in core or contrib

Proposed resolution

Add a ConditionsFormTrait or a "conditions" form element to core

Remaining tasks

Discuss
Implement
Release

User interface changes

None

Introduced terminology

API changes

Data model changes

Release notes snippet

Feature request
Status

Active

Version

11.0 🔥

Component

plugin system

Created by

🇩🇪Germany Anybody Porta Westfalica

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

Comments & Activities

Production build 0.71.5 2024