Drupal: automatically add new nodes to a nodequeue

試著忘記壹切 提交于 2019-12-01 23:20:07

问题


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


回答1:


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);
}



回答2:


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




回答3:


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

http://drupal.org/project/auto_nodequeue




回答4:


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:


You cannot set it up within the admin interface, but you can do it in a custom module using hook_nodeapi op insert.




回答6:


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




回答7:


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.



来源:https://stackoverflow.com/questions/3529874/drupal-automatically-add-new-nodes-to-a-nodequeue

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!