首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >我应该在Drupal 8而不是votingapi_set_vote()中使用什么?

我应该在Drupal 8而不是votingapi_set_vote()中使用什么?
EN

Drupal用户
提问于 2018-10-06 07:13:53
回答 1查看 422关注 0票数 1

VotingAPI 文档已经过时了。votingapi_set_vote()已在Drupal 8中删除。

我应该用什么代替它来以编程方式设置选票(例如在迁移中)?

EN

回答 1

Drupal用户

回答已采纳

发布于 2018-10-24 04:57:41

你知道如何以编程方式设置选票吗?

代码语言:javascript
运行
复制
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个投下的选票。因此,您必须为每一次投票运行此代码。

票数 1
EN
页面原文内容由Drupal提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://drupal.stackexchange.com/questions/270495

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档