I've been looking at porting a module to 7.x (it is dependent upon rules) but can't find any updated docs on d.o. Is the best place to look in the rules module itself? I've found the rules.api.php which has been helpful, but I was wondering if there was maybe some better docs somewhere else. Thanks.

Comments

BenK’s picture

I need this too... anyone have any links?

--Ben

fago’s picture

Category: support » task
Priority: Normal » Critical

Indeed, that's still missing. We'll have to do this docs asap.

Some first remarks coming to my mind:

action/condition info:
* The 'arguments' key has been renamed to 'parameter'. If there is a set of options to choose from, specify an 'options list' callback. Also it is possible to restrict the input mode for a parameter using the new 'restrict' key. For parameters that should be saved upon successful action evaluation set 'save' to TRUE. Return FALSE to customly skip saving.
* The 'new variables' key has been renamed to 'provides'.
* Now all parameters need to be specified, textual parameters automatically are supported by input evaluation - thus the 'input eval' key is gone.
* The configuration form is generated out of the parameters an usually already fine. For adapting it there is now a _form_alter callback as well as a _process and _validate callback that allows validation and processing of the $settings, which has to happen independent of the $form submission.
* Rules now obeys access permissions. Add appropriate access callback for using your provided action/condition info.

For events the
* The 'arguments' key has been renamed to 'variables'.
* Rules now obeys access permissions. Add appropriate access callback for using the event.

For provided data types or data properties provide entity metadata, e.g. by implementing hook_entity_property_info(). Intelligent saving is only supported for entities. Metadata for non-entity data structures may specified using hook_rules_data_info().

Changed data types:
* Rules makes use of the same data types as entity metadata recognizes for hook_entity_property_info(). Thus also list is supported, as well as a generic 'entity' type. 'string' got renamed to 'text'.

Changed file inclusion:
* Keep your hooks in yourmodule.rules.inc, but support for rules_forms.inc have been removed. All callback may reside in the .rules.inc file.
* Specify further include files using hook_rules_file_info(). All action or condition implementations may reside in any of those files or any other anytime included file.

fago’s picture

Issue tags: +rules-2-ALPHA
Berdir’s picture

A few questions, I'm working on rules integration for Privatemsg and Userpoints.

- Userpoints already has the concept of entity type and entity id since Drupal 5 and uses that to reference a "points transaction" (example user 1 gets 5 points in category X) to a node or comment or something like that. Currently, these are two separate fields when creating an action. I'd like to make this into a single action where you could select the entity and I can somehow get the type and id of that. Any suggestions?

- Is it possible to provide a default value for arguments (input mode)?

- If there is only a single possible value when using data selection (example, check userpoints condition on userpoints event), is it possible to automically select that value? (Similiar to above but probably not the same)

More to come :)

fago’s picture

ad 1)
I'd suggest to make a single variable 'entity' and pass an entity metadata wrapper as value for it. You can do $wrapper = entity_metadata_wrapper($type, $id) to create, so the entity is lazy-loaded on demand. However for the entity being really useful with Rules we need to add an "Entity is of type" condition to Rules - which makes sense anyway, but has not been implemented yet. With that condition it would be possible to configure a rule ala

if entity is a node
do something node related (e.g. publish the node)

For the points transaction, you could define a new rules data type. For an example look at the watchdog support shipping with Rules (system.module integration).

ad 2)
You can set the 'default value' key, however as of now the UI doesn't make use of it (but the API). I'd suggest to just set it, as soon as we've implemented this UI improvement it will work.

ad 3)
Sounds good, definitely something we need to add. Patches are welcome ;)

fago’s picture

fago’s picture

Status: Active » Fixed
Berdir’s picture

Awesome, http://drupal.org/node/905632 is exactly that the piece that I was missing.

One last question then, I've seen that there is now support for lists, but I'm not sure how to define a data type that contains such a list. To give an example, a private message can have multiple recipients, they are stored as an array of user objects in the recipients property. In D6, I executed the "private message sent" for every recipient, but If I'm understanding this right, then it should be possible to to this in a single event now, with a list of recipients?

fago’s picture

To provide a list of user objects, just use a variable with the data type list<user> and pass a numerically indexed array of user ids (or user objects).

However, it sounds like you'd have a separate data structure for messages? In that case, just add a property "recipients" being a list of users. See http://drupal.org/node/878876. Hope that helps :)

Did you manage to provide a variable of type "entity" as suggested above? If not, I can help you with that.

Berdir’s picture

Ok, will try that.

I found out why it wasn't able to declare it through hook_rules_data_info(). privatemsg_message is fieldable but doesn't use EntityController yet to load but rules knows it as an entity anway because it is declared using hook_entity_info(). So I had to declare the properties in hook_entity_properties_info().

Next problem there:

- EntityStructureWrapper::getPropertyInfo() replaces _ with -: "$name = str_replace('_', '-', $name);". Why is it doing that? Because I have a property named "thread_id", and if I define it like that, it throws an exception and if I define it as "thread-id", then it works fine but obviously isn't going to find the related data. Do I need to define a getter callback?

- Will try the list thing. I wasn't sure if that works because rules only defined list, list and list, but I guess it's intelligent enough to figure out what list means then?

- Haven't been able to look at the entity thing yet, will get back to you as soon as it is working.

PS: This discussion/questions probably don't really belong in this issue, especially since it's marked as fixed. Should I open new support requests for questions? Anyway, thanks for your help on this.

fago’s picture

I found out why it wasn't able to declare it through hook_rules_data_info(). privatemsg_message is fieldable but doesn't use EntityController yet to load but rules knows it as an entity anway because it is declared using hook_entity_info(). So I had to declare the properties in hook_entity_properties_info().

Oh, great. So just specify your callbacks or use the entity CRUD API for getting CRUD support in Rules too: http://drupal.org/node/878876

- EntityStructureWrapper::getPropertyInfo() replaces _ with -: "$name = str_replace('_', '-', $name);". Why is it doing that? Because I have a property named "thread_id", and if I define it like that, it throws an exception and if I define it as "thread-id", then it works fine but obviously isn't going to find the related data. Do I need to define a getter callback?

Let's handle that in #909728: fix property-rename problems.

>Should I open new support requests for questions?
Sounds good :) Feel free to ping me if I miss one of your issues ;)

Status: Fixed » Closed (fixed)
Issue tags: -rules-2-ALPHA

Automatically closed -- issue fixed for 2 weeks with no activity.