I saw there was an example (rules_test_ui_embed) for embedding rules conditions like we had in D7 - payment conditions etc., but it was only for embedding a single condition set (one configuration object).
In a few contribs we maintain, config entities have to have arbitrary conditions that rule conditions in D7 satisfied.
Sad to see that Commerce decided to use core conditions which really are not useful out of the box once your conditions get more complicated than checking a role. Ubercart has the code commented out where it checks Rules conditions. So with no examples to go on I looked at Rules core and derived from there. Quiz seems to be the only contrib that will use it so far, so I wanted someone to check this approach before I write a doc on drupal.org
https://www.devinzuczek.com/drupal/attaching-rules-conditions-to-a-confi...
Comments
Comment #2
djdevinComment #3
tr commentedThat looks good, and it would be great to have some of this documented. There's currently no documentation other than the code for using the UI components, and no documentation other than the tests for creating rules components programmatically. We could use some simple examples for the tr_rulez:rules_examples module (which will eventually be moved into Rules proper) in addition to written documentation in the Rules Documentation Guide.
One note - the replacement for
hook_default_rules_configuration()in D8 is to provide default components via config files. See for example tests/modules/rules_test_default_component/config/install/rules.component.rules_test_default_component.ymlHas any of this been committed to Quiz yet? Ubercart needs some similar code for the UI, but I haven't even started to do that yet since I've been trying to get Rules into shape first.
Also, take a look at #2470627: [Meta] Rules 8.x integrations for contrib modules and add Quiz to that issue if you think it's appropriate - links to other modules that have done Rules integration in D8 are very useful when trying to figure things out with limited documentation.
Comment #4
djdevinGreat, yes I saw that Rules are config now - I was pointing out specifically the case where you need to dynamically generate rules which we did previously in the default hook. I'll update the doc to be more clear about that.
https://git.drupalcode.org/project/ubercart/-/blob/7.x-3.x/payment/uc_pa...
https://git.drupalcode.org/project/quiz/-/blob/7.x-5.x/quiz.rules_defaul... (<- what this is replacing)
Thanks for the input, will update the docs when I get everything in place. I haven't committed it yet but I will soon, just working through some unrelated issues regarding the integration.
What's really nice is now that quiz "feedback types" are a config entity, with a component embedded, when you export the feedback type, the component comes with it :)
Comment #5
djdevinHere's the commit in Quiz that includes an updated test (passes with Rules 3.x-dev). I updated #2470627: [Meta] Rules 8.x integrations for contrib modules with a link too.
https://git.drupalcode.org/project/quiz/commit/296305e
Bonus: default entity configurations with embedded components!
Any preferred place to add documentation? I'll pull the technical bits from my blog post.
Comment #6
tr commentedWell, the documentation is currently a bit of a mess. The official documentation guide is https://www.drupal.org/docs/8/modules/rules, but there's nothing there yet. The D7 documentation is still mostly relevant from a user point of view - most of the concepts are the same, and most of the steps are the same, the big differences are the token syntax and the screen shots. But the D7 documentation hasn't been completely moved from the old "book" form to the new "guide" form because the automated tools on drupal.org used to migrate from old to new don't work for even moderately-sized documentation books, let alone for for a large complex set of documentation like we have with Rules - all the migration has to be done manually, and it requires admin intervention to preserve the URL aliases (super necessary because there are literally thousands of pages that link to the documentation). There is still some of this migration to be finished and the resulting D7 guide still needs to be cleaned up an re-organized.
The D8 documentation guide should be constructed in a manner similar to D7, by copying over pages from the D7 guide and updated them for D8 syntax page-by-page. I have not started on that, and no-one else has worked on it at all.
So there's essentially a blank slate - you can create any guides and pages within the D8 documentation guide that you think are necessary. Or you can put your documentation under https://www.drupal.org/docs/8/modules/d8-rules-essentials which is what I'm using as a staging area for creating mostly developer-related documentation. This will eventually be merged with the Rules documentation after the features and UI being developed in that project are moved into Rules (a lot of that has already happened ...).
I think it's more important to get it documented first without worrying too much about the right place to put it, because everything needs major re-organization anyway.
Let me know if you run into any permissions problems - I believe anyone should be able to add pages and guides without a problem, but since no-one has that's an untested theory.
I added a "related issue" link relevant to this issue - there needs to be more test cases for a lot of these things. That will serve both as documentation and insurance that we don't break your working code with other changes being made to Rules. If you are able to work on that, it would also help a lot. As far as I know, no one but you is currently working on this aspect of Rules at the moment, so feel free to propose any API changes you think will make this whole feature more usable.
Comment #7
djdevinAdded doc here: https://www.drupal.org/docs/8/modules/d8-rules-essentials/for-developers...