Global Context Variables

Last updated on
1 November 2021

Global context variables are available to all Rules conditions and actions. These variables show up in the data selector with a "@" at the beginning of their name. Drupal core provides only four global context variables:

  1. @language.current_language_context:language_interface
  2. @language.current_language_context:language_content
  3. @user.current_user_context:current_user - This is the "user" object for the current user.
  4. @node.node_route_context:node

Global context variables are always in scope and always available. These variables may be selected in data selection mode, or used in direct input mode by enclosing them in {{ }}, thus designating them as tokens.

Other modules may provide their own global context variables. Likewise, you may define your own global context variables if you need additional functionality. See Defining your own Global Context Variables for details about how to do this.

You can use drush to discover all the global context variables available for use on your site:
drush php-eval "print_r(array_keys(\Drupal::service('context.repository')->getAvailableContexts()));"

The Rules module defines three new global context variables:

  1. @rules.current_path_context:current_path
  2. @rules.current_date_context:current_date
  3. @rules.site_context:site

The Typed Data API module, required by Rules, gives you a simple drush command, which makes it easier to find the available global context variables on your site:

drush typed-data:context

Here are some other ideas for global context variables. These may possibly be implemented in Rules Essentials in the future:

Help improve this page

Page status: No known problems

You can: