![](/img/trans.png)
[英]How can I merge Nodes & Webform Submissions into instances of one general Content Type in Drupal 6?
[英]How to programically add all the nodes of content type article to one group in drupal 8?
我正在尋找一種將內容類型文章的所有節點添加到組id = 25的組的解決方案,是否有任何方法可以通過PHP代碼將其添加一次,我聽說過group中的功能addcontent,但是我沒有知道如何使用它,請幫幫我
Group::addContent(ContentEntityInterface $entity, $plugin_id, $values = [])
如何使用以上功能?
有什么方法可以執行一步步驟嗎?
Group::addContent(ContentEntityInterface $entity, $plugin_id, $values = [])
我需要將所有內容類型的文章與gid = 25分組
可能會有所幫助
$ group-> addContent($ entity,'group_node:article');
plugin_id實際上是節點類型
請嘗試一下。
讓我嘗試解釋更多
使用Drupal \\ node \\ Entity \\ Node; 使用Drupal \\ group \\ Entity \\ Group;
/**
* Implements hook_ENTITY_TYPE_insert().
*/
function yourmodulename_node_insert(Node $node) {
if ($node->bundle() == 'article') {
$pluginId = 'group_node:article';
// Here create some logic to load/chose the group id's you want to
// add the content to
// ...
foreach ($group_ids as $gid) {
$group = Group::load($gid);
$group->addContent($node, $pluginId);
}
}
}
我希望它會更清楚,foreach意味着您可以添加到多個組,因此在這里您可以嘗試自己的邏輯,即要添加到哪個組,希望這樣做有意義。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.