You are here

public function RateVote::validateVoteValue in Rate 8

Validates whether a value is allowed for a given vote type.

Parameters

$vote_type_id: Vote type id.

$value: The vote value.

Return value

bool Returns TRUE if the value is allowed, FALSE otherwise.

1 call to RateVote::validateVoteValue()
RateVote::vote in src/RateVote.php
Record a vote.

File

src/RateVote.php, line 202

Class

RateVote
Returns responses for Rate routes.

Namespace

Drupal\rate

Code

public function validateVoteValue($vote_type_id, $value) {
  $allowed_values = [
    -1,
    1,
  ];
  if ($vote_type_id == 'fivestar') {
    $allowed_values = [
      1,
      2,
      3,
      4,
      5,
    ];
  }
  return in_array($value, $allowed_values);
}