Selection

Last updated on
4 September 2022

Drupal 7 will no longer be supported after January 5, 2025. Learn more and find resources for Drupal 7 sites

By default, Rules includes a direct input and a data selection interface. The NodeOne video tutorial on Data types and data selection also covers this topic.

Data Selection

The data selection input method allows you to drill down into the data available to Rules, in that particular context. One important benefit from data selection is the ability to explore chained variables – for example node:author:… will show you data for a node's author, without the author's user object being explicitly loaded into Rules.

rules_data_selection.png

  • If selecting an item ending with ':' you can access data inside that object, creating chains of related data.
  • Modules like References and Entity Reference will provide connections between entities, such as user:field_node_reference:nid.
  • If you are expected to provide data of a certain type, the data selector will only list data end points matching these requirements. For example, if you are using an action to set a node title, Rules will only accept data of the type 'text'.

Direct Input

The direct input mode is most useful when entering a new text token, rather than another available data variable. You can use all chains of data found with the data selector as tokens in direct input mode. For example, you can use [user:field_node_reference:nid] as a token representing the node ID of a referenced node.

rules_direct_input.png

Additional info

Rules uses an incredibly extensible plugin system to support multiple types of data input interfaces. You can read more about this API and how to add additional data selection interfaces in the developer documentation section on data types.

Lists and items within them are also types of data which can be selected.

Selection of custom fields

For entities with custom fields, you must first create a condition that sets the entity bundle type, this will allow Rules to determine the fields available for the bundle, which can then be used for comparison, etc.

To do this, add a first condition to your rule as follows:

  1. From the 'Select the condition to add' input, select Entities > Entity is of bundle.
  2. Press Continue
  3. From the 'Data selector' input select the entity you are targeting (don't use the entity with the colon, e.g. Person, not Person:).
  4. Press Continue.
  5. You should now see a new 'Entity Bundle' fieldset, select the bundle name that you want to compare field values from.
  6. Press Save.

Now you can add additional conditional rules that have access to all of the custom fields belonging to the bundle you referenced in step 5.

NB The field type you created needs to match the field type that is expected, otherwise it will not show in the selector, eg if you have a Date field, but the entity is expecting a text field!

Help improve this page

Page status: No known problems

You can: