Global Context Variables
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:
- @language.current_language_context:language_interface
- @language.current_language_context:language_content
- @user.current_user_context:current_user - This is the "user" object for the current user.
- @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:
- @rules.current_path_context:current_path
- @rules.current_date_context:current_date
- @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
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