protected function FivestarItem::getVoteOwner in Fivestar 8
Get owner for vote.
In order to get correct vote owner need to do it based on fivestar field settings, when selected "Rating mode viewing" mode, then have to use current user. For "Rating mode editing" mode - if entity have method "getOwner" use entity owner, otherwise the current user has to be used.
Parameters
\Drupal\Core\Entity\FieldableEntityInterface $entity: The entity from which try to get owner.
string $rating_mode: Determines under what conditions a user can leave a review.
Return value
\Drupal\Core\Session\AccountInterface The account of the vote owner.
1 call to FivestarItem::getVoteOwner()
- FivestarItem::postSave in src/
Plugin/ Field/ FieldType/ FivestarItem.php - Defines custom post-save behavior for field values.
File
- src/
Plugin/ Field/ FieldType/ FivestarItem.php, line 362
Class
- FivestarItem
- Plugin implementation of the 'fivestar' field type.
Namespace
Drupal\fivestar\Plugin\Field\FieldTypeCode
protected function getVoteOwner(FieldableEntityInterface $entity, $rating_mode) {
switch ($rating_mode) {
case 'editing':
if ($entity instanceof EntityOwnerInterface) {
return $entity
->getOwner();
}
// Fall through.
case 'viewing':
default:
return \Drupal::currentUser();
}
}