I'm working on integrating CCK with rules. This includes a condition to check values of fields, an action to populate field values and two actions to load referenced nodes / users.
Note that I wanted to write the "populate a field" action as core action, however I found no way to do a multistep form there, so I gave that up and concentrated on a rules compatible action.
status of the patch
* user/node reference actions work fine
* populate field action basically works, but needs polishing
* the condition will be added once the action as done, as both can share 99% of the code.
Known bug: I've got the AHAH functionality working in the populate a field action configuration form, but the form dies due to the activation of form caching. Forms without AHAH work fine. (It let me run over http://drupal.org/node/299672 though :)
I'm posting this although it's not ready yet, as I'd like to get feedback from other devs:
* I'd like to get the integration into CCK instead of letting rules provide it - as it's the way it should be: rules provides hooks and CCK makes use of them. The include files are automatically conditionally included by rules anyway and of course I'd help maintaining it.
* The populate a field action is similar to the default value stuff in the field configuration screen. It embeds the fields form and also allows using PHP code. So I think reusing the validation routine for it would make sense. For that I'd like to factor that part out of _content_admin_field_validate(), so it can be reused.
* The content.rules.inc is sitting in the module main directory, as unfortunately this is required that rules can find it. Is this a problem?
* I've split the integration into three parts, so that the integration of the user/node reference fields goes into their modules. Is this ok, or should I combine this into one include conditionally adding in the actions for user/node reference once their modules are activated?
Current patch attached as well as a screenshot, showing the "populate a field" configuration form with an example field.
| Comment | File | Size | Author |
|---|---|---|---|
| #11 | cck_rules_integration_new.patch | 15.5 KB | fago |
| #8 | cck_rules_integration_3.patch | 15.5 KB | amitaibu |
| #7 | Snap1.png | 27.85 KB | amitaibu |
| #7 | Snap2.png | 30.71 KB | amitaibu |
| #3 | cck_rules_integration_patch.txt | 15.02 KB | fago |
Comments
Comment #1
yched commentedI have not delved into rules module (yet ?), and I don't think I'll have much time to maintain / provide support for this, so if you're ready to maintain it, fine by me. Karen, what do you think ?
...factor that part out of _content_admin_field_validate()
Why not.
The content.rules.inc is sitting in the module main directory, as unfortunately this is required that rules can find it. Is this a problem?
Yes, that's not too cool. Other 3rd party integration code lies in /include, so I'd really like if we kept it that way. Views module automatically searches root module folder and /includes folder - maybe steal some code there ?
I've split the integration into three parts
Fine by me.
Comment #2
fago>Views module automatically searches root module folder and /includes folder - maybe steal some code there ?
Ok, I can add this.
Comment #3
fagoso, back from drupalcon I've done more work on this.
* I've moved content.rules.inc into the include folder
* the patch provides now also "Field has value" and "Field has changed" conditions
* I've done some work on getting the rules multistep form to work with contributed code and #ahah callbacks. I got it all working :)
I've also found some formapi shortcomings during working on this, see http://drupal.org/node/302240 for more.
-> the ready patch is attached. :)
As said I'm happy to help maintaining this when it goes in. Could we also add a component "Rules integration" to the issue tracker? :)
Note: Due to the improvements to the rules admin form, you need the latest rules module to test the patch.
Comment #4
amitaibufago,
I've noticed you have some functions called
workflow_ng_...is it in purpose?Comment #5
fagoyes it is - it's the upgrade path from d5 workflow-ng installations. see http://drupal.org/node/299303
Comment #6
fagoupdate: I've just released rules beta 2 - so to use this patch just install beta2 or later.
Comment #7
amitaibuAttached patch fixes Call-by-reference error in lines 228, 231, 234.
Also fix some typos/ styling issues in the comments.
Two things that still needs to be worked IMO:
1. snap1 - the token replacement shouldn't appear in the 1st 'select field' page.
2. snap2 - The token replacement shouldn't appear if the field isn't a textfield (unless you can use it in the PHP code, in that case the token replacement should be below PHP code.
Comment #8
amitaibuThe token replacement issue is unrelated, I'll open a different issue for it.
I've also added a user-friendly message when there are no user/node reference fields.
@Fago please go over the changes.
Comment #9
mercmobily commentedHi,
Just to make sure you know in case you don't... Fago is on holiday, he'll be back on the 21st of September!
Merc.
Comment #10
Flying Drupalist commentedvery sweet, subscribe.
Comment #11
fagothanks for the improvements, amitaibu. Yes the token issue is unrelated to this one, but a separate one.
Additionally to your changes I've just removed an unnecessary empty line and changed the description of the node/user-reference field selects a bit. I've tested it again, it's working fine. So I think it's ready now.
Comment #12
karens commented@fago, looks like we're not getting a new release out as fast as we had hoped, so you don't have to wait on getting this in. You can go ahead and commit it whenever you think it's ready.
Comment #13
fagook, I've done so and committed this. thanks!
-> I've also added a new component to the issue tracker: "Rules Integration" - I hope that's ok so. :)
Comment #14
Flying Drupalist commentedDo you mean this is in the latest dev?
Comment #15
fagoyep, just install the latest snapshot.
Comment #16
hass commentedThis committed patch needs work. There are many translation bugs inside and strings that are not t'ified.
Comment #17
karens commented@fago, can you please take care of this?
Comment #18
fagoI do. What strings do you talk about hass?
I've already noticed the
Comment #19
fagoI've opened a new issue for this, please continue the discussion there. -> http://drupal.org/node/316354
Comment #20
Anonymous (not verified) commentedAutomatically closed -- issue fixed for two weeks with no activity.