You are here

function hook_rate_can_vote in Rate 8.2

Determine if user can vote.

Provide a way for custom checks of user ability to vote.

Parameters

bool $can_vote: Boolean to determine if user can vote.

\Drupal\votingapi\Entity\Vote $vote: An array of rate widget options.

object $entity: The voted entity object.

\Drupal\Core\Session\AccountProxy $account: The current user account.

1 invocation of hook_rate_can_vote()
RateWidgetBase::canVote in src/Plugin/RateWidgetBase.php
Checks whether currentUser is allowed to vote.

File

./rate.api.php, line 126
Provides hook documentation for the Rate module.

Code

function hook_rate_can_vote(&$can_vote, \Drupal\votingapi\Entity\Vote $vote, $entity, \Drupal\Core\Session\AccountProxy $account) {

  // Forbid user to vote on all other entities except for article.
  if ($entity
    ->bundle() != 'article') {
    $can_vote = FALSE;
  }
}