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
Issue fork tab_title_attention-3482684
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
Comment #2
anybodyPS: 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)
Comment #3
anybodyThe 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...
Comment #4
anybodyOkay 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!
Comment #5
anybodyHere are the best implementation of Condition Plugins I've found for a settings page:
Comment #6
anybodyComment #8
anybodyLet's see if that works basically ...
Comment #9
anybodyYay, it works!! :)
Now the condition validation...
Comment #10
anybodyCredits 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!!
Comment #11
anybodyPlease 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!
Comment #12
grevil commentedAdded some final comments! Otherwise, LGTM! 🙂👍
Comment #13
anybodyAll done!
Comment #14
grevil commentedThanks for the adjustments!
New changes LGTM!
Comment #15
grevil commentedThis should fix the tests (hopefully).
Comment #16
grevil commentedAll green!
Comment #18
grevil commented