Can I somehow automatically add a node to a specific nodequeue when it is created ?
(I\'m using nodequeue module: drupal.org/project/nodequeue)
thanks
There's a simple module made just for this purpose, for both Drupal 6 and Drupal 7:
http://drupal.org/project/auto_nodequeue
While this module does not exactly meet the OP "auto add" request it does allow you to configure the content type so that you can add it directly to the queue: https://www.drupal.org/sandbox/rlhawk/1444496 It is a sandbox but very stable and I use it all the time and love it.
I needed this feature for a drupal 7 site and took the custom module solution. Let's say the setup is one nodequeue, and every 'project' nodes should be automatically added and removed to the queue. Create an empty nodequeue_auto_add directory in sites/all/modules/. This contains these two files
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);
}
You cannot set it up within the admin interface, but you can do it in a custom module using hook_nodeapi op insert
.
I'm using drupal 5 which doesn't have rules. This is how I accomplished it, I'm not using any subqueues:
if($op == 'insert'){
if($node->type == 'node_type'){
$queue = nodequeue_load(4);
$subqueue = nodequeue_load_subqueue(4);
nodequeue_subqueue_add($queue, $subqueue, $node->nid);
}
}
There is an action "Add to Nodequeue" in Rules. I've solved by creating a new rule.