You are here

function rate_vote_type_access in Rate 8

Same name and namespace in other branches
  1. 8.2 rate.module \rate_vote_type_access()

Implements hook_ENTITY_TYPE_access().

File

./rate.module, line 449
Hook implementation code for the Rate module.

Code

function rate_vote_type_access(EntityInterface $vote_type, $operation, AccountInterface $account) {

  // If the user has the 'view rate results page' permission, we grant 'view'
  // access to all of the vote_type configuration entities defined
  // by the Rate module.
  $rate_types = [
    'updown',
    'fivestar',
  ];

  // Allow users with the permission 'view rate results page' to view metadata
  // about any of the vote types provided by this module.
  if (in_array($vote_type
    ->id(), $rate_types)) {
    switch ($operation) {
      case 'view':
        return AccessResult::allowedIf($account
          ->hasPermission('view rate results page'))
          ->cachePerPermissions()
          ->cachePerUser();
      default:
        return AccessResult::neutral();
    }
  }
  else {
    return AccessResult::neutral();
  }
}