Closed (fixed)
Project:
Rules
Version:
8.x-3.x-dev
Component:
Rules Core
Priority:
Major
Category:
Bug report
Assigned:
Unassigned
Reporter:
Created:
19 Jan 2016 at 03:06 UTC
Updated:
18 Apr 2020 at 19:19 UTC
Jump to comment: Most recent
how do I define a @condition which extends \Drupal\rules\Core\RulesConditionBase and which can sit unnoticed in my module if rules is not installed.
Otherwise I'm forced to put my modules rules in a separate module.
Should the rules @condition plugin type not be separate from the core @condition plugin type?
Comments
Comment #2
fagoOuch, that's indeed quite problematic. We could make a separated plugin and pass plugins through by default by having a deriver for that? Quite some extra implementation work for that though.
Instead, maybe it's enough to define a new Annotation class @RulesCondition and override the core condition manager to pick it up also. That way it should be ignored as long as Rules is not there.
Imo the better solution would be plugin module dependencies, but as that's not into 8.0.x it's out of scope for now. We could work on this but it wouldn't be usable before 8.1, what's not very helpful for being able to provide condition plugins now.
Comment #3
tr commentedIt turns out that a solution for this has been available in core since 2014, although it is undocumented, unused, and largely unknown. Even @fago didn't know about it, and he was heavily involved in core at the time. This feature had been in core for almost two years before this issue was opened!
The solution is described in the change notice: Plugins can depend on a module
This is a feature added to the DefaultPluginManager in order to allow plugins to declare a dependency on one (and only one) module. This only works for plugins that use a plugin manager derived from DefaultPluginManager. Because that is true of the ConditionManager, this feature will work for @Condition plugins.
To make this work, add the key/value
provider = "rules"to your condition's annotation. When discovering plugins, the plugin manager will examine this key. If the module specified in the value ("rules" in this case) is not available, the plugin manager will not try to load the plugin.I will be making use of this in Rules so we don't need submodules in order to provide Rules support for optional core modules (e.g. the "ban" module and in D8.8+ the new "path_alias" module).