Rules module provides a very powerful infrastructure to define conditionally executed actions based on occurring events. Let’s say a major upgrade to the core Triggers module. It makes a lot of sense to use Rules with Token module to create robust triggers, actions and even workflows without writing a single line of code.
For a recent project, I needed to access the vote value provided by the Voting API and use it with Rules. Strangely enough, when I checked the tokens available to Rules (which is very comprehensive), I realized that the vote value was not available.
Once I figured out that there is no very easy solution for that, I started to look for the easiest way to overcome that inconvenience and further ones. Custom Token module came to my help.
Use the following code to create a custom token (Type=Node) via the Custom Token module. This will make the vote of the logged-in user be available anywhere the regular tokens are available.
$criteria = array('content_type' => 'node', 'content_id' => $node->nid, 'uid' => $user->uid);
$user_vote = votingapi_select_single_vote_value($criteria)/10;
Author: Kayra (16)