For some tasks, rules requires to know the bundle of a given entity, the most obvious situation being when you need to set a field of a node and rules requires the type of node.

Normally you can solve this in the "condition" side of rules, where you can check that your entity is of a given bundle or that it has a specific field. However there are situation where this approach is not possible, as when the entities derives from the result of an action, in my case they are loaded from a VBO view. Hence how can you tell rules that a given list of entities - or a single entity - is of a given bundle, so I can use its specific fields ?

1 Answer 1


Actually, if you need to do something that's like an additional 'condition-then-action' within your rule's Action section, what you need is a Rules component!

You've loaded some entities in your action (perhaps in a loop) and now you need to apply a condition and action to those entities. Here's the basic recipe for using components in your action section:

  • Go to /admin/config/workflow/rules/components to create a new rule component to run for each of the items in your loop (or for a single item you've gotten in your rule action). Click the 'Add new component' link at the top of the page
  • Select 'Rule' from the drop-down options, since this will be a component that contains both a condition and an action
  • Name the rule, and in the 'Variables' section, we have to let it know we're going to pass it a parameter to work with. In your case, this will be the entity you want to check.
  • Once you've named your components and named the parameter you'll pass it, the next screen looks very much like a regular rule. Just set up the condition (make sure the entity is of type whatever) and the action (use the appropriate fields of that entity to do something).
  • Finally, save your component and call it in your original rule's action section (within the loop if you have one), passing it the entity to work with

Sorry that this is rather text-y. I actually just recently answered a question about using rules components with commerce items in another question and included screenshots there, so see if you can use that as a reference too: https://stackoverflow.com/questions/17797285/drupal-commerce-order-object-extra-data/17843597#17843597

Let us know if rule components solve your issue!

  • Hello, thank you. I couldn’t use this approach as I had to work on the whole list of entities (they are sent in a single email). I have tried to pass the whole list of entities to the component and then used the Rules List Conditions to check bundle on each element, but it didn't work. I ended up using the Conditional Rules module that, while still little buggy, it did the work.
    – Antonello
    Jul 31, 2013 at 10:28
  • Cool! Thanks for letting us know what ended up working for you! Jul 31, 2013 at 12:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.