I need help understanding data selectors

Events happening in the community are now at Drupal community events on www.drupal.org.
steenbob's picture

Hi!

I'm trying to use data selectors in Rules 2.0 on Drupal 7.x. It seems like a very promising feature, but I feel like I really don't understand enough about it.

a) Can I only use the data that appears in the list dynamically, or can I access any data as long as I understand the syntax?

b) How exactly does the syntax work and what does it mean?

Thanks!
Ben

Comments

Only appearing data

itangalo's picture

You can only access data that appears in the list, while using data selectors. (When using direct input, though, only a subset of the possible tokens are listed under replacement patterns. You can use any piece of data that appears in data selection mode, using the same syntax as for tokens – such as [node:author:uid] or [comment:node:author:uid].)

The exact dynamics of data selectors (and its syntax) is beyond me, but I know that it is built on the metadata declared for entities (and possibly other data types in Rules). For example, nodes are declared to have an author – and these are declared to be user objects. User objects, in turn, are declared to have (for example) uid and also a list of roles. To get the first role defined for a node author, you can use node:author:roles:0 (or something like that).

Furthermore, things like the node reference module provides further metadata to entities – tying in new node data, allowing patterns like node:related_node:title.

An important aspect of node references (and other fields) is that Rules must know that the node at hand has the desired field – if you have several node types, then Rules can't assume that a general node contains the desired field. You usually tell Rules this by adding the condition "entity has field" or "content is of type".

That's kind of it. It seems a bit messy at first, but when you come to understand it, it is really useful.
Understanding Rules' data handling is probably the best way to start learning Rules.

Good luck!
//Johan Falk
**
Check out NodeOne's Drupal Learning Library! 150+ screencasts and exercises, for Drupal introduction, advanced configuration, and coding.

Thank you for your help. I've

steenbob's picture

Thank you for your help. I've really come to learn a lot more about Rules in the last week or so.

A screencast now available

itangalo's picture

I just posted a screencast explaining data selectors – check out the second episode at http://nodeone.se/node/984 if you're interested.

Cheers!
//Johan Falk
**
Check out NodeOne's Drupal Learning Library! 180+ screencasts and exercises, for Drupal introduction, advanced configuration, and coding. Creative Commons license!

Thanks for the info, this is

klucid's picture

Thanks for the info, this is very helpful.

I'm working with Rules to notify Organic Group members of new content, but I only want them to be notified if the OG is flagged by the user.

I have Rules working well, up until the "USER ON WHOSE BEHALF TO CHECK". How can I use the data selector to check if users in the group have the content flagged?

Thanks again!

Hi there

nicodv's picture

Hello Johan, got your book (great job, btw) and i understand clearly the idea behind rules. I've created many rules so far but i'm now in front of a difficult problem: i need ro tell the site to let a role publish only 4 events, but of course there is not a data selector that counts nodes, so i'm starting to think that i need to create a custom data selector, is that right? Any tip to look in the right place and read or watch the correct tutorial?

Thanks

Field (or data selector)

itangalo's picture

It is possible to do this by coding your own data selector, but I would probably go about this using a field on user accounts – which is increased by one every time a user posts a piece of content. You will then also have to take into account that content might be deleted, or change author, and you should of course also prevent users from editing this field manually.

Maybe a selector is easier and quicker.

If you wanna try adding this with data selection, you'll have to add a new property to the user entity. Check out this example on how to add entity properties for a quick start: https://docs.google.com/document/d/1tkiFqWrJ9Df0PMnpbc5ibCkkROwMKuINvPWq...

Good luck!
//Johan Falk

Thanks a lot for the tip

nicodv's picture

I'll start with it first thing in the morning.

Thanks a lot again

Nico

Redirect anonymous user

stutibhavsar's picture

I want to redirect anonymous user to a specific node.
In event, I have selected "content is viewed".
What I am supposed to select in Data Selector?

Using Rules to update Taxonomy on Forum Topics

pjmcghee's picture

Hi! Rules IS awesome, but like much of Drupal, rather complicated. I need some help .

I have a Vocab (it references a location) that has been added to the User Account and to the Forum Topic Content Type via a Term Reference field type.
I need to use Rules to allow the user who is creating a Forum Topic to automatically update the Vobcab term on the topic. That way, the geographic location of the user will be attached to the Forum Topic.

I have all this completed in Rules, but the rule updates that field for ALL the nodes in Forum Topics and not just the current one. Can anyone help me out on this?

Thanks! PJ

Rules

Group organizers

Group categories

Categories

Group notifications

This group offers an RSS feed. Or subscribe to these personalized, sitewide feeds: