You are here

function like_and_dislike_can_vote in Like & Dislike 8

A helper method to check if passed user has enough permission to vote.

Parameters

\Drupal\Core\Session\AccountInterface $account: The account.

string $vote_type_id: The vote type ID.

\Drupal\Core\Entity\EntityInterface $entity: The entity.

Return value

bool TRUE in case user can vote. Otherwise, FALSE.

2 calls to like_and_dislike_can_vote()
LikeDislikeVoteBuilder::build in src/LikeDislikeVoteBuilder.php
Lazy builder callback for displaying like and dislike icons.
VoteController::voteAccess in src/Controller/VoteController.php
Checks if the currentUser is allowed to vote.

File

./like_and_dislike.module, line 109
This module provides 2 voting widgets: Like and Dislike.

Code

function like_and_dislike_can_vote(AccountInterface $account, $vote_type_id, EntityInterface $entity) {
  return $account
    ->hasPermission("add or remove {$vote_type_id} votes on {$entity->getEntityTypeId()}") || $account
    ->hasPermission("add or remove {$vote_type_id} votes on {$entity->bundle()} of {$entity->getEntityTypeId()}");
}