I have very simple reaction rule condition 'Node is Type' in Drupal 8 (8.5.3) Rules module (8.x-3.0-alpha3):

Data selector: @node.node_route_context:node

(Note: the mentioned issue occurs also for simple value node in the data selector.)

Content types: page

It works well when a node is viewed, but the rule causes crash with the error message The website encountered an unexpected error. Please try again later. when a node is previewed (button 'Preview' is clicked on the node form).

Note: To replicate the issue you should clear the cache on node form before hitting the 'Preview' button to ensure the node isn't served from the Drupal cache in which case Rules aren't fired.

The logged Error Message is:

Drupal\rules\Exception\EvaluationException: The context for node is NULL,
but the context node in rules_node_is_of_type requires a value.

Any hints on better Rules condition to catch the node type, or a patch for Rules?

Thank you!

  • 1
    Unless you need the rule to fire/trigger on the preview page (Can't think of any reason why you would...) you could set the rule to not trigger on node/preview/* path.
    – Beebee
    May 10, 2018 at 11:03
  • Under the hood, you'll probably find some component is trying to load a node with nid 'preview' if that is indeed the path format. May 10, 2018 at 11:23
  • Thanks @Beebee! However, I see no way how to order the elements in the conditions in D8 Rules GUI (thus the node type condition could throw an exception before the path condition can exclude the Rule from firing), nor I have an option to create a negative condition... :(
    – Michal Gow
    May 10, 2018 at 11:23
  • Thanks @AlfredArmstrong - I believe that is the case. That is actually my question: if it is an (unknown) bug, I shall open a ticket on Rules and do the job with entity_view hook (which is safe and much easy to use than Rules API), OR I do something stupid which can be fixed by better condition...
    – Michal Gow
    May 10, 2018 at 11:27
  • @MichalGow I'd seen the same bug in custom code written for Drupal 8. May 10, 2018 at 14:59

1 Answer 1


I have found a workaround.

It seems that this is indeed a bug in the Rules module. The working solution is from here (although it was originally written for different situation, it fits this case as well): https://www.drupal.org/project/rules/issues/2929588#comment-12385257, and basically suggests to use a different condition:

Rule condition: 'Condition: Data comparison'
Data to compare (switched to data selection): node.type.target_id (Content type ID)
Operator (switched to Direct Input mode): ==
Value (switched to Direct Input mode): your_node_type

I hope this helps somebody.

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.