Hi, I am trying to add nodes to an entity subqueue using Rules, but my changes actually never get saved. I verified that my events if being fired.
The first action I am using is "Fetch entity by id", and I specify my ID in the when setting it up. This is working, the subqueue gets loaded.
Then I use a custom action, that takes 2 parameters: the subqueue, and the node to be added. Here is the code:

/**
 * Add a node to a subqueue
 */
function add_node_to_entityqueue($subqueue, $node){
	$subqueue->eq_node[LANGUAGE_NONE][] = array('target_id' => $node->nid);
	entityqueue_subqueue_save($subqueue);
}

I can't add some debugging in this function to check that the subqueue and the node are loaded. But for some reason the subqueue is not being saved.

Can you help me with this?

Thanks,

Comments

jojonaloha’s picture

Status: Active » Postponed (maintainer needs more info)

I think there might be something wrong with your rule or action definition. If you can provide the exports, that might help. Here is the code I have for both that seems to work fine for me.

<?php // in a demo.module file
/**
 * Implements hook_rules_action_info().
 */
function demo_rules_action_info() {
  return array(
    'add_node_to_entityqueue' => array(
      'label' => t('Add Node to Entityqueue'),
      'parameter' => array(
        'subqueue' => array('type' => 'entityqueue_subqueue', 'label' => t('Subqueue')),
        'node' => array('type' => 'node', 'label' => t('Node')),
      ),
      'group' => t('Custom'),
      'base' => 'add_node_to_entityqueue',
    ),
  );
}
/**
 * Add a node to a subqueue
 */
function add_node_to_entityqueue($subqueue, $node){
  $subqueue->eq_node[LANGUAGE_NONE][] = array('target_id' => $node->nid);
  entityqueue_subqueue_save($subqueue);
}

Exported rule. Note: I have the devel module enabled and am using the debug value action in my rule to see that it is working.

{ "rules_add_to_queue" : {
    "LABEL" : "Add to Queue",
    "PLUGIN" : "reaction rule",
    "OWNER" : "rules",
    "REQUIRES" : [ "rules", "devel", "demo" ],
    "ON" : { "node_insert--gallery" : { "bundle" : "gallery" } },
    "DO" : [
      { "entity_fetch" : {
          "USING" : { "type" : "entityqueue_subqueue", "id" : "5" },
          "PROVIDE" : { "entity_fetched" : { "subqueue" : "Subqueue" } }
        }
      },
      { "devel_debug" : { "value" : [ "subqueue" ] } },
      { "add_node_to_entityqueue" : { "subqueue" : [ "subqueue" ], "node" : [ "node" ] } },
      { "devel_debug" : { "value" : [ "subqueue" ] } }
    ]
  }
}
amateescu’s picture

Status: Postponed (maintainer needs more info) » Closed (cannot reproduce)

Cleaning up the issue queue :)

kbrinner’s picture

I know this issue has been closed, but for those who like me were looking to create a custom action using entityqueue, it appears there are a couple of gotchas here. I found that if I didn't start the callback function with my custom module's name (ie [MYMODULE]) I would just get an error ''Unknown action" after selecting the custom action from the dropdown.

For the above example, I had to rename add_node_to_entityqueue to demo_add_node_to_entityqueue.

Here's the full code:

/**
 * Implements hook_rules_action_info().
 */
function [MYMODULE]_rules_action_info() {
  return array(
    '[MYMODULE]_add_node_to_entityqueue_action' => array(
      'label' => t('Add Node to Entityqueue'),
      'parameter' => array(
        'subqueue' => array('type' => 'entityqueue_subqueue', 'label' => t('Subqueue')),
        'node' => array('type' => 'node', 'label' => t('Node')),
      ),
      'group' => t('Custom'),
      'base' => 'add_node_to_entityqueue',
    ),
  );
}
/**
 * Add a node to a subqueue
 */
function [MYMODULE]_add_node_to_entityqueue_action($subqueue, $node){
  $subqueue->eq_node[LANGUAGE_NONE][] = array('target_id' => $node->nid);
  entityqueue_subqueue_save($subqueue);
}
jojonaloha’s picture

For those interested in Rules integration, we are accepting patches in #2474519: Add support for Rules

glynster’s picture

I am needing this for a Drupal 8 project. What needs to be adapted so this will be recognized in Rules @kbrinner?

lokeshsn22’s picture

Can you please provide the same for Drupal 8. I need tp update the queue progrmatically once after the node is added. Can some one help me out in this.

Pls’s picture

http://cgit.drupalcode.org/auto_entityqueue/tree/auto_entityqueue.module... - this module does the job of automatically adding to queue, and this code is perfect example how you can implement it yourself on Drupal 8.