gpt4 book ai didi

Drupal:自动将新节点添加到节点队列

转载 作者:行者123 更新时间:2023-12-03 23:15:41 25 4
gpt4 key购买 nike

我可以在创建节点时以某种方式自动将节点添加到特定的节点队列吗?

(我正在使用节点队列模块:drupal.org/project/nodequeue)

谢谢

最佳答案

我需要这个功能用于 drupal 7 站点并采用了自定义模块解决方案。假设设置是一个节点队列,每个“项目”节点都应该自动添加和删除到队列中。在 sites/all/modules/中创建一个空的 nodequeue_auto_add 目录。这包含这两个文件

nodequeue_auto_add.info

name = Nodequeue auto add/remove
description = Automatically adds and remove nodes when they are created and deleted.
core = 7.x
version = 7.x-dev
package = Nodequeue

dependencies[] = nodequeue

nodequeue_auto_add.module
<?php
/**
* Implements hook_node_insert().
*/
function nodequeue_auto_add_node_insert($node) {
$nid = $node->nid;
$type = $node->type;
// only process project node
if ($type != 'project') {
return FALSE;
}
// I've only one nodequeue where a specific node type should always be
// added so this is taken from the mysql nodequeue_queue table
$queue_id = 1;

// subqueue id, exists even if we created a really basic nodequeue (from nodequeue_subqueue table)
$sqid = 1;
$queue = nodequeue_load($queue_id);
$subqueue = nodequeue_load_subqueue($sqid);

if (function_exists('views_invalidate_cache')) {
views_invalidate_cache();
}

nodequeue_subqueue_add($queue, $subqueue, $nid);
}

/**
* Implements hook_node_delete().
*/
function nodequeue_auto_add_node_delete($node) {
$nid = $node->nid;
$type = $node->type;
// only process project node
if ($type != 'project') {
return FALSE;
}

if (function_exists('views_invalidate_cache')) {
views_invalidate_cache();
}

// I've only one nodequeue where a specific node type should always be
// added so this is taken from the mysql nodequeue_queue table
$queue_id = 1;

// subqueue id, exists even if we created a really basic nodequeue (from nodequeue_subqueue table)
$sqid = 1;

nodequeue_subqueue_remove_node($sqid, $nid);
}

关于Drupal:自动将新节点添加到节点队列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3529874/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com