Rate
Provides flexible voting widgets for Drupal content entities including nodes and comments with multiple widget templates and comprehensive voting features.
rate
Install
composer require 'drupal/rate:^3.2'
composer require 'drupal/rate:^3.1'
composer require 'drupal/rate:^3.0'
Overview
The Rate module delivers a comprehensive voting and rating system for Drupal sites, extending VotingAPI with a rich set of configurable widgets. Administrators can create multiple voting widgets with different visual styles and attach them to any content entity type or comment type.
The module supports seven built-in widget templates: Custom (fully customizable), Fivestar (5-star rating), Thumbs Up, Thumbs Up/Down, Number Up/Down, Emotion (emotional reactions like funny/mad/angry), and Yes/No voting. Each widget can be configured with custom options, labels, CSS classes, and result display settings.
Voting is performed exclusively via AJAX for a seamless user experience. The module includes sophisticated bot detection mechanisms using user agent patterns, IP-based thresholds, and BotScout.com API integration. Vote rollover settings control how frequently users can change their votes, with separate settings for anonymous and authenticated users.
A voting deadline feature allows administrators to close voting on specific dates by adding a date field to content types. The module provides a Voting Results tab on nodes displaying detailed vote breakdowns. Full Views integration enables displaying rate widgets in any view with flexible display options.
Features
- Multiple widget templates: Custom, Fivestar, Thumbs Up, Thumbs Up/Down, Number Up/Down, Emotion, and Yes/No
- Attach single or multiple rate widgets to any content entity type
- Comment voting support for all comment types
- AJAX-only voting for seamless user experience
- Undo/cancel votes by clicking the same option again
- Bot detection via user agent patterns, IP thresholds, and BotScout.com API
- Vote rollover settings for anonymous and authenticated users
- Voting deadline feature with automatic field creation on entities
- Voting Results tab for nodes showing detailed vote breakdowns
- Views integration with Rate Widget field plugin
- Customizable widget labels, descriptions, and result summaries
- Position controls for labels (inline/above/hidden), descriptions, and results
- Read-only widget mode for display without voting
- Migration support from Drupal 7 Rate module
- Custom vote result functions (average, count, sum) per widget
- Dynamic permission generation per entity type and bundle
Use Cases
Article Rating with 5-Star System
Add a 5-star rating widget to article content type. Create a fivestar widget, select 'Article' under entities, configure display to show average rating, and enable the rate widget in Article's Manage Display. Users can rate articles 1-5 stars and see the community average.
Comment Voting (Like/Dislike)
Enable voting on comments with thumbs up/down. Create a thumbsupdown widget, check the Comment column for the desired content type, set appropriate permissions for 'Can vote on comment_field on node type of article'. Comments will show like/dislike buttons with vote counts.
Poll-Style Yes/No Voting
Create a simple yes/no voting widget for decision-making content. Use the yesno template, enable on a custom content type, configure to show option counts rather than user votes. Ideal for community polls or feedback collection.
Time-Limited Voting Contest
Run a voting contest with deadline. Create a widget with 'Use vote deadline' enabled. When editing content, set the deadline date. After the deadline passes, the widget becomes read-only automatically, preserving final results.
Emotional Reactions (Like Facebook)
Add reaction buttons similar to social media. Use the emotion template or create a custom widget with options like 'Love', 'Haha', 'Wow', 'Sad', 'Angry'. Configure to show count for each option.
Product Reviews in Views
Display rate widgets in a product listing view. Add the Rate Widget field to your view, select which field contains the entity ID, choose whether to show full widget, read-only, or summary only. Override display options as needed for compact view listings.
Tips
- Use 'Votingapi setting' for rollover windows to maintain consistent voting rules across all widgets via the central VotingAPI configuration.
- Create theme suggestions for rate-widgets-summary to customize result display per widget type or content type (e.g., rate-widgets-summary--fivestar--article.html.twig).
- For high-traffic sites, lower bot detection thresholds to 10/50 to catch vote manipulation attempts more quickly.
- Use the hook_rate_can_vote() hook to implement custom voting restrictions like requiring content authorship, group membership, or other business logic.
- When displaying widgets in Views, use relationships to VotingAPI results to enable sorting and filtering by vote totals or averages.
- Disable logging in production for better performance if you don't need vote event audit trails.
Technical Details
Admin Pages 6
/admin/config/search/votingapi/rate
Configure global Rate module settings including bot detection thresholds and BotScout.com API integration. This page allows administrators to set up automated bot blocking to prevent vote manipulation.
/admin/structure/rate_widgets
View and manage all rate widgets defined in the system. Lists all widgets with their machine names, templates, and provides links to edit or delete each widget.
/admin/structure/rate/add
Create a new rate widget by selecting a template and configuring all voting options, entity assignments, display settings, and result display preferences.
/admin/structure/rate/{rate_widget}/edit
Modify an existing rate widget's configuration including options, entity assignments, display settings, and result preferences.
/admin/structure/rate/{rate_widget}/template
Change the template type of an existing rate widget. Warning: this will overwrite current options and value type settings.
/node/{node}/node-rating
Displays detailed voting results for a specific node including per-option vote counts and sums, plus a views-based results listing. Only visible for nodes with rate widgets attached.
Permissions 4
Hooks 5
hook_rate_vote_data_alter
Alter the vote data array before a vote is created in the database. Allows modifying entity type, bundle, value type, and custom vote data columns.
hook_rate_widget_options_alter
Override the options (value, label, class) of a rate widget before it is rendered. Called before the rate form is generated.
hook_rate_value_column
Assign an alternative database column to retrieve rate values from. By default, votes are stored in the 'value' column, but custom modules can specify different columns.
hook_rate_templates
Define additional or modify existing templates for rate widgets. Templates specify value type, options, customizability, and translation settings.
hook_rate_can_vote
Provide custom checks for determining if a user can vote. Allows modules to implement additional voting restrictions beyond standard permissions.
Troubleshooting 6
Check that: 1) The rate widget is enabled for the correct entity type and bundle in widget configuration, 2) The rate widget pseudo-field is enabled in Manage Display for that content type, 3) The content is not in preview mode (widgets don't render on new unsaved content).
Ensure users have the dynamic voting permission 'Can vote on [entity_type] type of [bundle]' at /admin/people/permissions. These permissions are generated automatically when widgets are assigned to entity types.
Check if the user is being detected as a bot. Review bot detection thresholds at /admin/config/search/votingapi/rate. Also verify vote rollover settings are not set to 'Never' if you want users to be able to change votes.
This is expected behavior when 'Use vote deadline' is enabled and the deadline has passed. To re-enable voting, edit the content and change or remove the Rate vote deadline field value.
Ensure 'Disable fontawesome' is unchecked in Rate settings. If your theme provides its own FontAwesome, you may need to enable that setting to avoid conflicts and rely on your theme's icons.
Run the d7_rate_widgets migration first to import widget configurations, then run the d7_vote migration to import actual votes. Ensure VotingAPI migrations have also been run.
Security Notes 4
- The 'Administer Rate options' permission should only be assigned to trusted administrator roles as it allows creating widgets that affect all users.
- Bot detection helps prevent automated vote manipulation but is not foolproof. Consider additional measures for critical voting scenarios.
- BotScout.com API key should be kept confidential. The key is validated but transmitted over HTTP to the BotScout API.
- Rate widgets on anonymous-accessible content can be subject to vote manipulation from users clearing cookies or using different browsers.