The selection list of conditions to add to a rule includes a section named 'Other' and these conditions do not work when selected. They often produce a blank form with no more selections or text entry. On further investigation these conditions are provided by Core and probably should not be included in this Rules selection list.

Here is an example - the items in the red block will vary depending on which other modules are enabled, as they do not come from Rules code.

selection list

The source of some of these items is as follows:

Node Bundle = core/modules/node/src/Plugin/Condition/NodeType.php
Current Theme = core/modules/system/src/Plugin/Condition/CurrentThemeCondition.php
Request Path = core/modules/system/src/Plugin/Condition/RequestPath.php
User Role = core/modules/user/src/Plugin/Condition/UserRole.php

They fall into the "Other" section as they have no category defined. The conditons are annotated with @Condition which is the same for the Rules conditions. However, for actions, the Rules ones are annotated with @RulesAction presumably to distinguish them from Core actions. So maybe we should use @RulesCondition for the conditions which are OK for this selction list.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

jonathan1055 created an issue. See original summary.

dasjo’s picture

We had to fork the actions api, but as far as i know we didn't have to fork the conditions api for rules yet. Ideally we should try to stay compatible which is why they show up.

Is there something missing for the core conditions that they don't work with rules?

tedbow’s picture

@dasjo just a quick look at the differences between: \Drupal\node\Plugin\Condition\NodeType(core) and \Drupal\rules\Plugin\Condition\EntityIsOfType(rules)

Here is what I think is happening
You can use NodeType in Rules but...

  1. You are given form with just "value" this is the Node context specified in NodeType. Rules does seems to understand this from the NodeType's annotation context section because if I try to use data selection and select a none node value it will warn me. It has not label or description because EntityIsOfType uses "label" and "description" in the context section of the annotation.
  2. The type is not available to choose because core conditions use \Drupal\Core\Condition\ConditionPluginBase::buildConfigurationForm to select this. The Rules UI seems to not call the this but rather figure this out by Conditions contexts.
  3. NodeType does not use the context annotation to define "type"(bundle)
  4. \Drupal\node\Plugin\Condition\NodeType::evaluate() does get called but because the configuration for the condition was never set it always returns true.

So obviously Rules conditions are more flexible and don't rely on hardcoded forms. So I am not sure if Rules ever calls \Drupal\Core\Plugin\PluginFormInterface::buildConfigurationForm for the conditions or uses the form logic at all. If it does not one way to make Rules with core conditions would be:

  1. have \Drupal\rules\Core\RulesConditionBase override all the methods from \Drupal\Core\Plugin\PluginFormInterface with empty implementations.
  2. Rules could addition to it's current logic call methods on PluginFormInterface. This is would have no effect for conditions that extend RulesConditionBase
  3. Core conditions could use their simple conditions. Maybe somehow label these as less dynamic.

This is my first look at Rule 8.x so I could be totally off 😉

tedbow’s picture

Status: Active » Needs review
FileSize
3.28 KB

Here is patch that simply gets the configuration form for core conditions to show up. The configuration doesn't save.

Just a note, most(all?) of the conditions are duplicated with conditions that Rules provides. So you might just want to remove the known ones.

fago’s picture

Status: Needs review » Needs work

Yeah I agree we should just hide the conditions which we replace with better alternatives.

For the others, just adding in the form + making sure it saves correctly should be the way go. Of course we need to figure out a common code path somehow here. Maybe we could just have the Rules' generated form be loaded in the same methods as core uses?

Setting to needs work as this is not finished.

TR’s picture

Nchase’s picture

I guess it would be the best for now to just hide those conditions, otherwise there will be continuous support requests and bug reports with error messages that result form trying to use Core conditions.

TR’s picture

Status: Needs work » Needs review
FileSize
1.41 KB

This patch hides the non-working core conditions from the Rules UI.

firfin’s picture

Status: Needs review » Reviewed & tested by the community

This indeed hides the 'other' category and the conditions in it. Applied cleanly.

When or how the to-do in the patch will be resolved is a question I still have though.

  • TR committed 328b1d2 on 8.x-3.x
    Issue #2927132 by TR, jonathan1055: List of conditions includes Core...
TR’s picture

Category: Bug report » Feature request
Status: Reviewed & tested by the community » Needs work

I committed this patch, primarily for the reason stated in #7.

But I'll keep this issue open to address the larger problem of using core Conditions in Rules.

dinazaur’s picture

The last committed patch also all default Block visibility conditions. Also, Rules conditions always are in the Block visibility conditions selection.

This patch just remove applied changes.

andypost’s picture

Status: Needs work » Needs review
TR’s picture

Status: Needs review » Needs work

It looks like this check should be made in the ConditionForm rather than in the ConditionManager, that way it will affect only Rules. I will post a new patch later. This issue is still "Needs work" for all the other things that need to be done - there is no new patch to review.

The problem of Rules conditions showing on the Block settings page is the subject of #2675698: Ensure compatibility with core block UI

You don't need to post a new patch, the changes can be reversed by applying the old patch with patch -R.

TR’s picture

@dinazaur: Try this - this should not remove the default conditions from block visibility, but should hide the core conditions from the Rules UI.

  • TR committed 0145364 on 8.x-3.x
    Issue #2927132 by TR, dinazaur: List of conditions includes Core...
  • TR committed da01be9 on 8.x-3.x
    Revert "Issue #2927132 by TR, jonathan1055: List of conditions includes...
TR’s picture

Status: Needs review » Needs work

I reverted the commit made in #10 to fix the Block visibility problem, and added the changes in #15 to restrict the core Conditions using the ConditionForm rather than the ConditionManager. This patch was reviewed and tested by several people in #3160347: Option of block page visibility is missing.

Back to NW for the rest of it...

  • TR committed a00b3df on 8.x-3.x
    Issue #2927132 by TR, dinazaur: List of conditions includes Core...
Mike.Brawley’s picture

#15 worked for me on drupal 8.8.8 and rules 8.x-3.0-alpha6

slowflyer’s picture

one more
#15 worked for me on drupal 8.8.8 and rules 8.x-3.0-alpha6

hristos’s picture

Thank's very very match. #15 work but I wasted all day wondering what it was, and I didn't know how to ask google. Thank you again!!!!

ab2211’s picture

#15 helped (Drupal 8.9.2 / Rules 8.x-3.0-alpha6).

ddhuri’s picture

Thanks #15 works for me with Drupal 8.9.6 and Rules 8.x-3.0-alpha6

ThoreauinSF’s picture

#15 worked - thank you

nchristensen’s picture

#15 worked (Drupal 8.9.10 and Rules 8.x-3.0-alpha6)

Mike.Brawley’s picture

#15 worked on 8.9.12 Rules 8.x-3.0-alpha6

Mike.Brawley’s picture

Status: Needs work » Reviewed & tested by the community

Changing this to reviewed and tested as the past 7 people have tested.

TR’s picture

Status: Reviewed & tested by the community » Needs work

Read the issue - the patch was committed 6 months ago . .

aiphes’s picture

I can't apply the patch on the D8914 + rules 8.x-3.0-alpha6

sited8/modules/contrib/rules$ wget -q -O - https://www.drupal.org/project/rules/issues/2927132#commen t-13761341 | git apply
error: unrecognized input

what is missing ?

jonathan1055’s picture

Hi aiphes,
Take a look at the command you pasted. You are trying to apply a comment link, you need the patch file.

aiphes’s picture

Exact. The right command is:
/sited8/modules/contrib/rules$ wget -q -O - https://www.drupal.org/files/issues/2020-07-23/2927132-15- remove-other-conditions-from-ui.patch | git apply

Thanks