Drupal: automatically add new nodes to a nodequeue

2019-02-25 09:03发布

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

7条回答
再贱就再见
2楼-- · 2019-02-25 09:47

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);
}
查看更多
来,给爷笑一个
3楼-- · 2019-02-25 09:55

There is an action "Add to Nodequeue" in Rules. I've solved by creating a new rule.

查看更多
一夜七次
4楼-- · 2019-02-25 10:01

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);
    }
}
查看更多
等我变得足够好
5楼-- · 2019-02-25 10:02

There is a module for that. Check it out and see if it helps. https://www.drupal.org/project/auto_nodequeue/project/auto_nodequeue

查看更多
Luminary・发光体
6楼-- · 2019-02-25 10:06

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.

查看更多
啃猪蹄的小仙女
7楼-- · 2019-02-25 10:08

There's a simple module made just for this purpose, for both Drupal 6 and Drupal 7:

http://drupal.org/project/auto_nodequeue

查看更多
登录 后发表回答