On this page
Availability of Data in Rules
Drupal 7 will no longer be supported after January 5, 2025. Learn more and find resources for Drupal 7 sites
Note to developers: See also the Developer Docs page on Data types for using hook_rules_data_info()
.
Exposing data values
When creating or editing an entity, properties must also be set separately using the "set a data value" action. Entity fields will only be available if you have used a condition to verify that the field is present or they are automatically exposed for that particular rule. By default their basic entity type properties should be exposed, but if you need access to a particular field that is limited to a certain entity bundle (e.g. node type), then you should use a condition on that first, e.g. check the content type of a node using the respective condition or the "data comparison" condition against the entity's type property. Most of the time this is simply some-entity:type
in the data select widget, but for taxonomy terms it is their vocabulary. As an alternative the "Entity has field" condition can be used, which is particularly useful if you do not know the type of your entity.
If any fields are common to all or some bundles of the relevant type, you can also use the 'data comparison' condition to expose all fields all checked bundles have in common without getting too specific. This can be advantageous in a situation where you want to set a field on an entity of a particular entity type, but the entity may be one of any number of bundle types. For example, if I was a rental company and had a vehicle 'entity type' and several bundles like 'car', 'truck', 'snowmobile', etc that all had the common field/property 'mileage'. I could make a rule to generically set the mileage value in my tracking system without having to know what type of vehicle was returned.
The Drupal Commerce Documentation, Why can't I access my custom fields in Rules? describes the same info as above with some references to older developments.
Discussion to improve this can be found @ #1421368: Action: "Modify an entity".
See the "Setting data values" documentation for an example on updating different content types, that are linked via an entity reference field. Useful if you are trying to figure out how to gain access to fields on a different content type.
Loading data values
Rules includes native support for EntityFieldQuery in the "Fetch entity by id" and "Fetch entity by property" actions. The values on an entity identified in an Entity Reference field can be loaded this way. A referenced entity is referred to as a "Parent data structure". Views Rules is also a useful tool for loading data using the familiar Views query building interface.
The action "Add a value" allows you to specify the type of the variable that should be added. This is useful for many purposes. In some cases, it can be used as a simple, yet reliable workaround for adding a variable to the set of exposed values. Additionally, it is useful as an intermediary value during series of calculations.
Help improve this page
You can:
- Log in, click Edit, and edit this page
- Log in, click Discuss, update the Page status value, and suggest an improvement
- Log in and create a Documentation issue with your suggestion