VotingAPI 文档已经过时了。votingapi_set_vote()
已在Drupal 8中删除。
我应该用什么代替它来以编程方式设置选票(例如在迁移中)?
发布于 2018-10-24 04:57:41
你知道如何以编程方式设置选票吗?
use Drupal\votingapi\Entity\Vote;
$vote = Vote::create(['type' => 'vote']); // this comes from /admin/structure/vote-types
$vote->setVotedEntityType('node'); // entity type
$vote->setVotedEntityId($nid); // node id
$vote->setValueType('points'); // this comes from /admin/structure/vote-types
$vote->setValue(1); // the number of points given per vote
$vote->setOwnerId($uid); // the user id of the person who casted the vote
$vote->setCreatedTime($timestamp) // timestamp of when vote was casted (optional)
// it will use the current time if you don't include it
$vote->save();
上述代码将创建1个投下的选票。因此,您必须为每一次投票运行此代码。
https://drupal.stackexchange.com/questions/270495
复制相似问题