We are running the dev branch of scheduler, and after doing a recent composer update, some ajax requests started returning:
Fatal error: Class 'Drupal\rules\Core\RulesConditionBase' not found in /modules/contrib/scheduler/src/Plugin/Condition/NodeIsScheduledForPublishing.php on line 23Installing the rules module solved the problem, but if rules is going to be a dependency, it should be listed as one.
This problem was originally reported by mikemccaffrey on #2651348-28: Port Rules integration for Scheduler to Drupal 8 but is better as a separate specific issue.
| Comment | File | Size | Author |
|---|---|---|---|
| #5 | 2790459-5.move_rules_to_submodule.patch | 68.2 KB | jonathan1055 |
Comments
Comment #2
jonathan1055 commentedWe do not want to insist that the Rules module is a requirement, because it is not needed for Scheduler. The rules components are provided for those who want to use them, they are entirely optional. The executable Scheduler code which triggers the events is protected inside calls to "moduleExists('rules')" and this works fine when running the site.
There must be some way to avoid the errors you have found. I'll do some investigation.
Jonathan
Comment #3
morsokIf you don't want to enforce a dependency on Rules (which is a good thing to me), then there is only one option since the auto-loader will always throws the missing class exception : you must put all the integration code into a sub-module (scheduler_rules maybe ?) which will depends on rules.
So the main scheduler module will not have the dependency and no errors, and if rules integration is needed you only have to activate the sub-module.
Comment #4
jonathan1055 commentedHi Morsok,
Thanks for the info, that is really helpful. Yes I had been thinking that a sub-module might solve the problem, but was not sure if there was a simpler way. But if the auto-loader will always detect the missing classes then it seems that a sub-module is the right solution.
I'll work on this, and hopefully it won't be too long before you get your alpha2 release :-)
Jonathan
Comment #5
jonathan1055 commentedI have moved all the Rules-related code out of the main module and into a sub-module
scheduler_rules_integration. In summary, this involved:scheduler_rules_integrationand add scheduler_rules_integration.info.ymlscheduler_rules_integration/src/Pluginscheduler_rules_integration/src/EventDrupal\scheduler\Plugin\ConditiontoDrupal\scheduler_rules_integration\Plugin\Condition(but the internal id is not changed)scheduler_rules_integration.moduleand move into it the Rules code from hook_node_presave() and hook_node_insert()SchedulerManager.phpand instead call a new function _scheduler_rules_integration_dispatch_cron_event() to invoke the cron eventsIf the Rules module is not enabled then scheduler_rules_integration cannot be enabled. This prevents the dependency errors as reported in this issue and in #2790471: When editing a block: Fatal error: Class 'Core\RulesConditionBase' not found
I have also tested each part manually and it all works OK. I have written tests to cover all the rules actions, conditions and events, before making this change, and checking it afterwards, and I am happy that it all works. However, uploading these tests does not currently work on drupal.org testbots - I have raised #2775519: Automated testing for 3rd-party modules integrating with Rules
@mikemccaffrey If it is possible for you to test this patch and see if your composer errors are corrected that would be very helpful.
Comment #6
slasher13Had the same problem. This patch fixed it. Didn't test the Rules integration.
Comment #8
jonathan1055 commentedThanks morsok for the advice and thanks slasher13 for the review.
This is a good fix. Committed and done.
Comment #9
jonathan1055 commentedUnassigning