Problem/Motivation

The settings page should allow to include / exclude certain conditions. Like roles, paths...

For that, Drupal provides condition plugins: https://www.previousnext.com.au/blog/using-drupal-8-condition-plugins-api
You can see their usage for example in blocks: https://www.therussianlullaby.com/blog/condition-plugins-for-visibility-...

But we don't want to add our own conditions, but use the available conditions instead of reinventing the wheel!
So conditions like path, roles, ... should be shown in the settings page

By default we should exclude typical paths like:

ajax/*
admin/*
batch/*
libraries/*
modules/*
profiles/*
sites/*
themes/*

Steps to reproduce

Proposed resolution

Remaining tasks

User interface changes

API changes

Data model changes

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

anybody created an issue. See original summary.

anybody’s picture

PS: You'll need to implement the same here (posthog module): #3481022: Implement typical configuration & exclusions settings

And we should write some documentation, as it seems to be super undocumented... (or isn't possible through Conditions API)

anybody’s picture

The context module for example also implements conditions very well, see https://git.drupalcode.org/project/context/-/blob/8.x-4.x/src/Entity/Con...

Maybe you want to install the module and try it out to get an idea and implement it likewise.
You should also be able to see relevant parts of the config schema there.

Unsure which other modules use it.

You can find the core implementation here: https://git.drupalcode.org/project/drupal/-/tree/11.x/core/lib/Drupal/Co...

anybody’s picture

Okay here you go: Various contrib sources: https://git.drupalcode.org/search?group_id=2&scope=blobs&search=Conditio...
Still I think context is one of the most reliable as widely used and mature!

Asset injector is another one, but both use entities. I'd like to find an example with a settings page...

I finally also found https://git.drupalcode.org/project/core_extend/-/blob/8.x-1.x/src/Form/C... in contrib, which would be super helpful and decided to create a core issue: #3482703: Provide a ConditionsFormTrait or form element for conditions
But we shouldn't wait for that!

anybody’s picture

anybody’s picture

Title: Use Drupal Conditions API to include / exclude by certain conditions » Use Drupal Conditions Plugin API to include / exclude by certain conditions

anybody’s picture

Assigned: lrwebks » Unassigned
Status: Active » Needs review

Let's see if that works basically ...

anybody’s picture

Yay, it works!! :)
Now the condition validation...

anybody’s picture

Credits to https://www.drupal.org/project/advanced_mautic_integration and https://www.drupal.org/project/lazyloader - their implementation helped me a lot to understand how condition plugins work. A lot of there code was used here, great work!!

anybody’s picture

Please note that currently the condition plugins are always affected by #3482723: Create an admin route condition plugin or add generic "Current theme" options for admin and default theme which leads to wrong results, as the "Current theme" condition is always evaluated with the preselected value!

grevil’s picture

Status: Needs review » Needs work

Added some final comments! Otherwise, LGTM! 🙂👍

anybody’s picture

Assigned: Unassigned » grevil
Status: Needs work » Needs review

All done!

grevil’s picture

Assigned: grevil » Unassigned
Status: Needs review » Reviewed & tested by the community

Thanks for the adjustments!

New changes LGTM!

grevil’s picture

Status: Reviewed & tested by the community » Needs review

This should fix the tests (hopefully).

grevil’s picture

Status: Needs review » Reviewed & tested by the community

All green!

  • grevil committed 21b9c723 on 1.x authored by anybody
    Issue #3482684: Use Drupal Conditions Plugin API to include / exclude by...
grevil’s picture

Status: Reviewed & tested by the community » Fixed

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.