Drupal: automatically add new nodes to a nodequeue

前端 未结 7 2097
旧巷少年郎
旧巷少年郎 2021-01-20 04:16

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条回答
  • 2021-01-20 04:53

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

    http://drupal.org/project/auto_nodequeue

    0 讨论(0)
  • 2021-01-20 04:54

    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.

    0 讨论(0)
  • 2021-01-20 04:59

    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);
    }
    
    0 讨论(0)
  • 2021-01-20 05:01

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

    0 讨论(0)
  • 2021-01-20 05:03

    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);
        }
    }
    
    0 讨论(0)
  • 2021-01-20 05:10

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

    0 讨论(0)
提交回复
热议问题