Here is what I'm trying to accomplish:
When a new user account is created, the user should automatically be added to an entityqueue. I have set up an entityqueue called 'User Queue', the Handler is 'Simple queue' and the Entity type is 'User'. The queue isn't restricted to a minimum or maximum. Here is the exported queue:
$queue = new EntityQueue();
$queue->disabled = FALSE; /* Edit this to true to make a default queue disabled initially */
$queue->api_version = 1;
$queue->name = 'user_queue';
$queue->label = 'User Queue';
$queue->language = 'en';
$queue->handler = 'simple';
$queue->target_type = 'user';
$queue->settings = array(
'target_bundles' => array(
'user' => 'user',
),
'min_size' => '0',
'max_size' => '0',
'act_as_queue' => 0,
);
I can manually add users to the queue at admin/structure/entityqueue/list/user_queue/subqueues/1/edit
I am trying to go off the Updating subqueue programmatically issue that discussed automatically adding nodes to a subqueue:
/**
* 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);
}
To create a rule to add any new users automatically to this entityqueue, I have the following:
Event: After saving a new user account
Action 2: Add User to Entityqueue (custom action in user_moderation module, see below), 'Subqueue' identifier: 1, 'User' Data selector: account.
/**
* Implements hook_rules_action_info().
*/
function user_moderation_rules_action_info() {
return array(
'user_moderation_add_user_to_entityqueue' => array(
'label' => t('Add User to Entityqueue'),
'parameter' => array(
'subqueue' => array('type' => 'entityqueue_subqueue', 'label' => t('Subqueue')),
'user' => array('type' => 'user', 'label' => t('User')),
),
'group' => t('Custom'),
),
);
}
/**
* Add a user to a subqueue.
*/
function user_moderation_add_user_to_entityqueue($subqueue, $user){
$subqueue->eq_node[LANGUAGE_NONE][] = array('target_id' => $user->uid);
entityqueue_subqueue_save($subqueue);
}
I think I understand creating a custom action through hook_rules_action_info() but it's the details of the callback function user_moderation_add_user_to_entityqueue where I suspect I am missing something.
When I test this by creating a new user, it isn't automatically added to the queue. I do know the rule is firing because if I add an action that is 'Show a message on the site' the message is displayed upon creating a new account.
Thank you for any help - I do mainly Drupal configuration and theming so this is a bit beyond my comfort zone.
Here is the exported Rule as well:
{ "rules_add_user_to_entity_queue" : {
"LABEL" : "Add user to entity queue",
"PLUGIN" : "reaction rule",
"OWNER" : "rules",
"REQUIRES" : [ "user_moderation", "rules" ],
"ON" : { "user_insert" : [] },
"DO" : [
{ "user_moderation_add_user_to_entityqueue" : { "subqueue" : "1", "user" : [ "account" ] } }
]
}
}
Comments
Comment #2
amateescu commentedClosing issues for the 7.x version, which is not supported anymore.