function hook_rate_vote_data_alter in Rate 8.2
Alter the vote data before a vote is created.
Override the input data sent to the entity storage to create a new vote. The array includes the entity id and type, the vote and value type, the user casting the vote and the rate widget used. The hook is called before the vote is created for the vote entity form.
Parameters
array $vote_data: An array of vote data sent to storage to create the vote.
string $entity_type: The voted entity type.
string $entity_bundle: The voted entity bundle.
int $entity_id: The voted entity id.
string $rate_widget: The rate widget being used for voting.
Drupal\rate\Entity\RateWidget $settings: The rate widget config entity and settings.
int $user_id: The user id casting the vote.
1 invocation of hook_rate_vote_data_alter()
- RateWidgetBase::getEntityForVoting in src/
Plugin/ RateWidgetBase.php - Returns a Vote entity.
File
- ./
rate.api.php, line 31 - Provides hook documentation for the Rate module.
Code
function hook_rate_vote_data_alter(array &$vote_data, $entity_type, $entity_bundle, $entity_id, $rate_widget, $settings, $user_id) {
// Trigger only on articles and specific widgets.
if ($rate_widget == 'test_rate_widget' && $entity_bundle == 'article') {
// Change the value type for the vote to be created.
$vote_data['value_type'] = 'points';
// Write data to a custom votingapi_vote column.
$vote_data['custom_column'] = 'some value';
}
}