What should I use in Drupal 8 instead of votingapi_set_vote()? VotingAPI docs are out of date. votingapi_set_vote() has been removed in Drupal 8.

What should I use in its place to programmatically set votes (for instance in a migration)?
Do you know how to set votes programmatically?


use Drupal\votingapi\Entity\Vote;

$vote = Vote::create(['type' =&gt; 'vote']); // this comes from /admin/structure/vote-types
$vote-&gt;setVotedEntityType('node'); // entity type
$vote-&gt;setVotedEntityId($nid); // node id
$vote-&gt;setValueType('points'); // this comes from /admin/structure/vote-types
$vote-&gt;setValue(1); // the number of points given per vote
$vote-&gt;setOwnerId($uid); // the user id of the person who casted the vote
$vote-&gt;setCreatedTime($timestamp) // timestamp of when vote was casted (optional)
// it will use the current time if you don't include it
$vote-&gt;save();


The above code will create 1 casted vote. Therefore, you will have to run this code for every single vote.